function varargout = myplacement(varargin) global a; global magp; global phasep; global impulsep; global zplanep; global placepoles placezeroes newpole showsurface showcookie surfacefig shownormalisedfreq; global clearpoles donenewpole N; %evalin('caller','if ~exist(''zeroes'') global zeroes; end;') evalin('caller','global zeroes;') global zeroes; if (isempty(zeroes)) zeroes=[]; end; %evalin('caller','if ~exist(''poles'') global poles; end;') evalin('caller','global poles;') global poles; if (isempty(poles)) poles=[]; end; if nargin == 0 action = 'init'; % shh = get(0,'ShowHiddenHandles'); % set(0,'ShowHiddenHandles','on') % spfig = findobj(0,'Tag','sptool'); % set(0,'ShowHiddenHandles',shh); % if ~isempty(spfig) % figure(spfig) % return % end else action = varargin{1}; eval(action); end %[a,magp,phasep,impulsep,zplanep]=placement2; switch action case 'init' % AJL STUFF (GLOBAL FLAGS) placepoles = 0; % we are noew playing with pole placement placezeroes = 1; % we are now playing with zero placement newpole = 0; % used to store a button press location on the zplane showsurface = 0; % show the z transform as a surface in separate figure showcookie = 0; % show the unit circle only as surface in sepearate figure surfacefig = 0; % seperate figure handle for surface drawing shownormalisedfreq = 0; % show in the seperate figure the freqz output clearpoles = 1; % whether to zero the list donenewpole = 0; % a flag if ~isempty(poles) clearpoles = 0; donenewpole = 1; else poles = []; % list of current poles end; if ~isempty(zeroes) clearpoles = 0; donenewpole = 1; else zeroes = []; % list of current poles end; N = 128; % number of samples in impulse response [a,magp,phasep,impulsep,zplanep]=placement2; % Generate a structure of handles to pass to callbacks, and store it. %handles = guihandles(a) %guidata(a, handles); % AJL now these are the remembered parts of the GUI % AJL STUFF (MAIN LOOP) %axes(zplanep); %if findstr(version,'5.2') == 1 % set(zplanep,'Color',[ 0 0 0]); %end; %axis([-1 1 -1 1]); %zgrid; %drawnow; if clearpoles == 1 myplacement('clearpoles = 1;'); % recursively call back to get first draw else myplacement('clearpoles = 0; donenewpole = 1;'); % recursively call back to get first draw end; otherwise %[obj,a] = gcbo; % a = gcbf figure(a) % handles = guidata(a) % handles2 = guihandles(a) % zplanep = handles2.zplane; % magp = handles2.mag; % phasep = handles2.phase; % impulsep = handles2.impulse; if clearpoles ~= 0 disp('Clearing all poles and zeroes'); clearpoles = 0; poles = []; zeroes = []; end; if newpole ~= 0 newpole =0; donenewpole = 1; % disp('Placing a singularity'); %%%%% figure(a); axes(zplanep); polelocation = ginput(1) if placepoles ~= 0 if polelocation(2) == 0 poles = [poles; (polelocation(1) + j*0)]; else poles = [poles; (polelocation(1) + j*polelocation(2))]; poles = [poles; (polelocation(1) - j*polelocation(2))]; end; end; if placezeroes ~= 0 if polelocation(2) == 0 zeroes = [zeroes; (polelocation(1) +j*0)]; else zeroes = [zeroes; (polelocation(1) + j*polelocation(2))]; zeroes = [zeroes; (polelocation(1) - j*polelocation(2))]; end; end; end; % work out the impulse response theimpulseresponse = zeros(1,N); theimpulseresponse(1) = 1; numerator = poly(zeroes); denominator = poly(poles); theimpulseresponse=filter(numerator,denominator,theimpulseresponse); hold off; axes(zplanep); %hold off; %cla; if findstr(version,'5.2') ~= [] set(zplanep,'Color',[ 0 0 0]); end; cla; hold off zgrid; hold on %pzmap(poles,zeroes); if poles ~= [] plot(poles,'*r') end hold on; if zeroes ~= [] plot(zeroes,'og') end axis([-1 1 -1 1]); hold off; axes(magp); dft = fft(theimpulseresponse); plot(abs(dft)); axes(phasep); plot(angle(dft)); axes(impulsep); plot(theimpulseresponse); drawnow; axes(zplanep); if showsurface ~= 0 showsurface = 0; if surfacefig ~= 0 figure(surfacefig); else surfacefig = figure; end; rationaltransformplot(poles,zeroes,2,'log'); drawnow;%figure(a) elseif showcookie ~= 0 showcookie = 0; if surfacefig ~= 0 figure(surfacefig) else surfacefig = figure; end; rationaltransformplot(poles,zeroes,2,'zringonly'); drawnow;%figure(a) elseif ((shownormalisedfreq ~= 0)&(donenewpole ~=0)) donenewpole = 0; if surfacefig ~= 0 figure(surfacefig) else surfacefig = figure; end; freqz(numerator,denominator); drawnow; %figure(a); end; end; %switch