home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / pzmap.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  85 lines

  1. # Copyright (C) 1996,1998 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function [zer,pol]=pzmap(sys)
  18. # function [zer,pol]=pzmap(sys)
  19. # Plots the zeros and poles of a system in the complex plane.
  20. #
  21. # inputs: sys: system data structure
  22. # outputs: if omitted, the poles and zeros are plotted on the screen.
  23. #          otherwise, pol, zer are returned as the system poles and zeros.
  24. #          (see sys2zp for a preferable function call)
  25.  
  26.   save_val = implicit_str_to_num_ok;    # save for later
  27.   save_emp = empty_list_elements_ok;
  28.  
  29.   implicit_str_to_num_ok = 1;
  30.   empty_list_elements_ok = 1;
  31.  
  32.   if(nargin != 1)
  33.     usage("pzmap(sys) or [zer,pol] = pzmap(sys)"); 
  34.   elseif (!is_struct(sys));
  35.     error("sys must be in system format");
  36.   endif
  37.  
  38.   [zer,pol] = sys2zp(sys);
  39.  
  40.   # force to column vectors, split into real, imaginary parts
  41.   zerdata = poldata = [];
  42.   if(length(zer))
  43.     zer = reshape(zer,length(zer),1);
  44.     zerdata = [real(zer(:,1)), imag(zer(:,1))];
  45.   endif
  46.   if(length(pol))
  47.     pol = reshape(pol,length(pol),1);
  48.     poldata = [real(pol(:,1)), imag(pol(:,1))];
  49.   endif
  50.  
  51.   # determine continuous or discrete plane
  52.   vars = "sz";
  53.   varstr = vars(is_digital(sys) + 1);
  54.  
  55.   # Plot the data
  56.   gset nologscale xy;
  57.   if(is_siso(sys))
  58.     title(sprintf("Pole-zero map from %s to %s", ...
  59.        sysgetsignals(sys,"in",1,1), sysgetsignals(sys,"out",1,1) ));
  60.   endif
  61.   xlabel(["Re(",varstr,")"]);
  62.   ylabel(["Im(",varstr,")"]);
  63.   grid;
  64.  
  65.   # compute axis limits
  66.   axis(axis2dlim([zerdata;poldata]));
  67.   grid
  68.   # finally, plot the data
  69.   if(length(zer) == 0)
  70.     plot(poldata(:,1), poldata(:,2),"@12 ;poles (no zeros);");
  71.   elseif(length(pol) == 0)
  72.     plot(zerdata(:,1), zerdata(:,2),"@31 ;zeros (no poles);");
  73.   else
  74.     plot(zerdata(:,1), zerdata(:,2),"@31 ;zeros;", ...
  75.       poldata(:,1), poldata(:,2),"@12 ;poles;");
  76.   endif
  77.   replot
  78.  
  79.   implicit_str_to_num_ok = save_val;    # restore value
  80.   empty_list_elements_ok = save_emp;
  81.  
  82. endfunction
  83.