You are on page 1of 2

%

%
%
%
%
%
%

Pole & zeros & frequency response


of a digital filter
- animation
Figure 4.23
BM
Dec 97

clear
clf
colordef(1,'black')
%
poles & zeros
Rp = 0.6;
thetap = 135;
thetap = thetap/180*pi;
pp = Rp*exp(j*thetap);
b = [1 0 ];
a = [ 1 -pp ];
zz = [0];
subplot(1,2,1);
zplane(b,a);
hold on
fprintf(1,'Figure 4.23: pole/zero plot - press return to continue\n')
pause
th = 0;
pt = exp( j*th/180*pi );
xx = real(pt);
yy = imag(pt);
l1 = line('Xdata',xx,'Ydata',yy);
set(l1,'Color','w','Marker','o','EraseMode','xor');
l2 = line('Xdata', real ([ pt pp(1)] ),'Ydata',imag([ pt pp(1)]),'Color','g','Li
neStyle','-','EraseMode','xor');
l4 = line('Xdata', real ([ pt zz(1)] ),'Ydata',imag([ pt zz(1)]),'Color','b','Li
neStyle','-','EraseMode','xor');
l6 = line('Xdata', real ([ 0 pt ] ),'Ydata',imag([0 pt ]),'Color','r','LineStyle
','-','EraseMode','xor');
M = 128;
[hh,w] = freqz(b,a,2*M,'whole');
%h = 10*log10(abs(hh));
h = abs(hh);
ang = unwrap(angle(hh))/pi*180;
angmax = max(ang);
angmin = min(ang);
maxh = max(h);
if min(h) < 0
minh = min(h);
else
minh = 0;
end
w = w/pi/2;
subplot(2,2,2)
xx = [ w(1) w(1) ];
yy = [ h(1) h(1) ];

ll1 = line ('Xdata',xx,'Ydata',yy,'Color','y','LineStyle','-','Erasemode','none'


);
ll2 = line ('Xdata',w(1),'Ydata',h(1),'Color','w','Marker','o','Erasemode','xor'
);
axis ([ 0 0.5 minh maxh ])
grid
ylabel ('gain')
xlabel ('frequency')
hold on
subplot(2,2,4)
xx = [ w(1) w(1) ];
yy = [ ang(1) ang(1) ];
lx1 = line ('Xdata',xx,'Ydata',yy,'Color','y','LineStyle','-','Erasemode','none'
);
lx2 = line ('Xdata',w(1),'Ydata',h(1),'Color','w','Marker','o','Erasemode','xor'
);
axis ([ 0 0.5 angmin angmax ])
grid
ylabel ('phase (degrees)')
xlabel ('frequency')
hold on
fprintf(1,'Figure 4.23:construction lines - press return to animate\n')
pause
step = 360/M;
for ii = 1:4:M+1;
th = (ii-1)*step/2;
pt = exp( j*th/180*pi );
set(l1,'Xdata',real(pt),'Ydata',imag(pt));
set(l2,'Xdata', real ([ pt pp(1)] ),'Ydata',imag([ pt pp(1)]));
set(l4,'Xdata', real ([ pt zz(1)] ),'Ydata',imag([ pt zz(1)]));
set(l6,'Xdata', real ([0 pt ] ),'Ydata',imag([0 pt ]));
if ii==1,
xx = [ w(1) w(1) ];
yy = [ h(1) h(1) ];
else
xx = w(ii-1:ii);
yy = h(ii-1:ii);
end
set(ll1,'Xdata',w(1:ii),'Ydata',h(1:ii));
set(ll2,'Xdata',w(ii),'Ydata',h(ii));
if ii==1,
xx = [ w(1) w(1) ];
yy = [ ang(1) ang(1) ];
else
xx = w(ii-1:ii);
yy = ang(ii-1:ii);
end
set(lx1,'Xdata',w(1:ii),'Ydata',ang(1:ii));
set(lx2,'Xdata',w(ii),'Ydata',ang(ii));
pause(1)
end

You might also like