image thumbnail

Filter Plot

by

 

Plotting of the zeros and poles of a digital filter.

zp_plot(option,a,b);
function zp_plot(option,a,b);
%---------------------------------------------------------------------------------------------
%Plotten der Nullstellen und der Pole eines digitalen Filters: 
% y[n] + a[1]*y[n-1] + ... + a[p]*y[n-p] =u[n] + b[1]*u[n-1] + ... + b[q]*u[n-q]
%
% 
%
% option=1,  a : Polen-Vektor , b :Nullstellen-Vektor
% option=2,  a=[a[1],a[2],...a[p]], b=[b[1],b[2],...b[q]], 
%
% Bemerk: a[0]=1 und b[0]=1 sind nicht in den Vektoren enthalten.


a=a(2:length(a));
b=b(2:length(b));
t = (0:1/500:1)'*2*pi;
for m=1:5
    l=(6-m)/5;
    x(:,m) = l*sin(t);
    y(:,m) = l*cos(t);
    plot(x(:,m),y(:,m),'k--');hold on;
    text(m*0.15,-m*0.15,num2str(m*0.2));
end
plot(x(:,1),y(:,1),'k');
axis equal
axis off
line([-1.2 1.2],[0 0],'color','k');
line([0 0],[-1.2 1.2],'color','k');
hold on;
plot(1.2,0,'>',0,1.2,'^','MarkerFaceColor','k','MarkerEdgeColor','k'); 
text(1.1,0.1,'Re','FontAngle','italic','FontName','Euclid Fraktur');
text(1.23,0.11,'(z)');
text(0.08,1.1,'Im','FontAngle','italic','FontName','Euclid Fraktur');
text(0.21,1.11,'(z)');
text(-1.2,0.72,'Einheitskreis','FontAngle','italic','FontName','Euclid Fraktur');

if option==1
    a = poly(a);
    a = a(2:length(a));
    b = poly(b);
    b = b(2:length(b));
end
a = a(:);
b = b(:);
p = length(a);
q = length(b);
if p ~= 0,
    pl=roots([1;a]);
    plot(real(pl),imag(pl),'x','MarkerFaceColor','r','MarkerEdgeColor','r','MarkerSize',8,'LineWidth',2);
end
if q ~= 0,
    zr=roots([1;b]);
    plot(real(zr),imag(zr),'o','MarkerEdgeColor','b','MarkerSize',5,'LineWidth',1);
end
if p-q==0
    return;
end
if q-p<0
    Mkr='o';
elseif q-p>0
    Mkr='x';
end
for m=1:abs(p-q)
    plot(0,0,Mkr,'MarkerEdgeColor','g','MarkerSize',5+4*(m-1),'LineWidth',1);
end

save zp.mat zr pl
end

Contact us