Search code examples
matlabgraphfilteringaxissequences

Plotting a zplot using Matlab


I am trying to plot a zplot in Matlab that displays a unit circle, centered at 0 along with the poles and zeros of the plot. I am not allowed to use any other matlab function such as zplane or pzplot to do this. So far I am able to plot a unit circle just fine but I am having trouble getting my plot to display more of the axis without warping my circle. I also am having a heard time finding the poles and zeros of my function and also how to display the poles as little x's and the zeros as little o's on my plot. Any help would be greatly appreciated! My assignment looks like this and must correctly handle cases such as

zplot([0 1 1], [0 1]); zplot([0 1 1], [0 0 1]);

function zplot(b, a)

% ZPLOT Plot a zero-pole plot.

                                              -1 -nb
              B(z) b(1) + b(2)z + .... + b(nb+1)z

     H(z) = ---- = ---------------------------------

                                              -1 -na
              A(z) a(1) + a(2)z + .... + a(na+1)z

% zplot(b, a) plots the zeros and poles which determined by vectors b and a

% The plot includes the unit circle and axes for reference, plotted in black.

% Each zero is represented with a blue 'o' and each pole with a red 'x' on the 
%plot.

xmin;   
xmax;

ymin;   
ymax; 

% vector of angles at which points are drawn

angle = 0:2*pi/100:2*pi;            

% Unit radius

R = 1;               

% Coordinates of the circle

x = R*cos(angle);  
y = R*sin(angle);  

% Plot the circle

plot(x,y);                             
axis ([xmin, xmax, ymin, ymax]);

grid on;

end

Solution

  • If you can't use pzplot() it is not hard. Here is a hint:

    num = [1 4 1];%numerator coefficients of transfer function
    den = [1 2 1];%denominator coefficients
    
    z = roots(num)%zeros
    p = roots(den)%poles
    
    angle = 0:2*pi/100:2*pi;
    xp = cos(angle);
    yp = sin(angle);
    
    figure(1)
    scatter(z,zeros(length(z),1),'o');
    hold on
    scatter(p,zeros(length(p),1),'x');
    plot(xp,yp);
    axis equal
    

    The output

    enter image description here

    Note that I haven't dealt with imaginary poles/zeros in this example. You'll need to calculate the proper x,y coordinates for a given imaginary pole or zero. (all the poles/zeros in this example are real, not imaginary)