function [poles,zeros]=pzplot2(b,a,ROC)
%PZPLOT plots the poles and zeros of a continuous-time LTI system.
%
% Usage:  [poles,zeros] = pzplot(b,a,ROC)
%
% The vectors 'a' and 'b' contain the coefficients of the denominator
% and numerator polynomials of the LTI system function. The optional
% argument ROC defines one point in the region of convergence. The
% locations of the poles and zeros are returned in 'poles' and
% 'zeros'.

%---------------------------------------------------------------
% copyright 1996, by John Buck, Michael Daniel, and Andrew Singer.
% For use with the textbook "Computer Explorations in Signals and
% Systems using MATLAB", Prentice Hall, 1997.
%---------------------------------------------------------------
MSIZE = 10;
LWIDTH = 2;

poles=roots(a); % determine poles
zeros=roots(b); % determine zeros
poles=poles(:); % make into column vector
zeros=zeros(:); % make into column vector

MaxI=max(abs(imag([poles; zeros;j]))); % Determine size of diagram
MaxR=max(real([poles; zeros;1])); % 
MinR=min(real([poles; zeros;-1]));
MI = 1.2*MaxI;
MxR = 1.2*MaxR;
MnR = 1.2*MinR;
plot([MnR MxR],[0 0],'m-')     % Plot the real axis
hold on
plot([0 0],[-MI MI],'m-')     % Plot the imag axis
set(gca,'FontName','Times');
set(gca,'FontSize',15);
set(gca,'LineWidth',1.2);
xlabel('Real Part'), ylabel('Imaginary Part')
plot(real(zeros),imag(zeros),'ro','markersize',MSIZE, ...
     'linewidth',LWIDTH)   % Plot zeros
plot(real(poles),imag(poles),'bx','markersize',MSIZE, ...
     'linewidth',LWIDTH)   % Plot poles

if nargin>2,                         % ROC optional
  if(any(real(poles)<ROC))           % Any poles to the left?
    lpole=max(real(poles(real(poles)<ROC)));
    plot([lpole lpole],[-MI MI],'g--')
  else
    lpole = MnR;
  end

  if(any(real(poles)>ROC))           % Any poles to the right?
    rpole=min(real(poles(real(poles)>ROC)));
    plot([rpole rpole],[-MI MI],'g--')
  else
    rpole = MxR;
  end

  NBARS = 8;
  aratio = (MxR - MnR)/(2*MI);
  t = linspace(lpole,rpole,200);
  l1 = 1/aratio * (t - lpole);
  l2 = 1/aratio * (t - rpole);
  for index = 0:NBARS
    offset = index*(MI/NBARS);
    plot(t,l1+offset,'g')
    plot(t,l1-offset,'g')
  end
  offset_initial = 1/aratio*(rpole-lpole) - offset;
  go = 1;  index = 0;
  while go
    offset = (index*(MI/NBARS) + offset_initial);
    plot(t,l2+offset,'g')
    index = index - 1;
    stop_val = 1/aratio*(rpole-lpole) + offset;
    if (stop_val < -MI)
      go = 0;
    end
  end
  h=text((lpole+rpole)/2,-0.75*MaxI,'ROC');        % Label the ROC
  set(h,'FontSize',14,'FontName','Times','FontWeight','bold', ...
      'HorizontalAlignment','center')
end

axis([MnR MxR -MI MI])
axis('square');                      % Make square aspect ratio
grid
hold off


