function varargout=mySplacement(varargin) global a; global magp; global phasep; global impulsep; global splanep; 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,splanep]=placementS; 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 %poles = []; % list of current poles %zeroes = []; % list of current zeros 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,splanep]=placementS; % AJL STUFF (MAIN LOOP) %axes(splanep); %if findstr(version,'5.2') == 1 % set(splanep,'Color',[ 0 0 0]); %end; %axis([-2 2 -2 2]); %sgrid; %c = get(splanep,'Children'); %for i=1:length(c) % set(c,'Color',[0 0 0.5]); %end; %drawnow; if clearpoles == 1 mySplacement('clearpoles = 1;'); % recursively call back to get first draw else mySplacement('clearpoles = 0; donenewpole = 1;'); % recursively call back to get first draw end; % AJL always do this part otherwise 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(splanep); 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 by first finding the freq response theimpulseresponse = zeros(1,N); theimpulseresponse(1) = 1; numerator = poly(zeroes); denominator = poly(poles); freqsamples = linspace(-2,2,N); [dft,freqsamples]=freqs(numerator,denominator,freqsamples); theimpulseresponse=fftshift(ifft(fftshift(dft))); axes(splanep); hold off; cla; if findstr(version,'5.2') == 1 set(splanep,'Color',[ 0 0 0]); end; axis([-2 2 -2 2]); sgrid; % c = get(splanep,'Children'); % for i=1:length(c) % set(c,'Color',[0 0 0.5]); % end; 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); plot(freqsamples,abs(dft)); axes(phasep); plot(freqsamples,angle(dft)); axes(impulsep); plot(real(theimpulseresponse)); drawnow; if showsurface ~= 0 showsurface = 0; if surfacefig ~= 0 figure(surfacefig); else surfacefig = figure; end; rationaltransformplot(poles,zeroes,2,'log'); drawnow; elseif showcookie ~= 0 showcookie = 0; if surfacefig ~= 0 figure(surfacefig) else surfacefig = figure; end; rationaltransformplot(poles,zeroes,2,'sfreqonly'); drawnow; elseif ((shownormalisedfreq ~= 0)&(donenewpole ~=0)) donenewpole = 0; if surfacefig ~= 0 figure(surfacefig) else surfacefig = figure; end; bode(numerator,denominator); drawnow; figure(a); end; end;