home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / pzmap.m < prev    next >
Encoding:
Text File  |  1999-12-15  |  2.6 KB  |  87 lines

  1. ## Copyright (C) 1996,1998 Auburn University.  All Rights Reserved.
  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. ## 
  10. ## Octave is distributed in the hope that it will be useful, but WITHOUT 
  11. ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  12. ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  13. ## for more details.
  14. ## 
  15. ## You should have received a copy of the GNU General Public License 
  16. ## along with Octave; see the file COPYING.  If not, write to the Free 
  17. ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. 
  18.  
  19. ## -*- texinfo -*-
  20. ## @deftypefn {Function File } {[@var{zer}, @var{pol}]=} pzmap (@var{sys})
  21. ##  Plots the zeros and poles of a system in the complex plane.
  22. ## @strong{Inputs}
  23. ##  @var{sys} system data structure
  24. ## 
  25. ## @strong{Outputs}
  26. ## if omitted, the poles and zeros are plotted on the screen.
  27. ##           otherwise, pol, zer are returned as the system poles and zeros.
  28. ##           (see sys2zp for a preferable function call)
  29. ## @end deftypefn
  30.  
  31. function [zer, pol]=pzmap (sys)
  32.  
  33.   save_emp = empty_list_elements_ok;
  34.  
  35.   empty_list_elements_ok = 1;
  36.  
  37.   if(nargin != 1)
  38.     usage("pzmap(sys) or [zer,pol] = pzmap(sys)"); 
  39.   elseif (!is_struct(sys));
  40.     error("sys must be in system format");
  41.   endif
  42.  
  43.   [zer,pol] = sys2zp(sys);
  44.  
  45.   ## force to column vectors, split into real, imaginary parts
  46.   zerdata = poldata = [];
  47.   if(length(zer))
  48.     zer = reshape(zer,length(zer),1);
  49.     zerdata = [real(zer(:,1)), imag(zer(:,1))];
  50.   endif
  51.   if(length(pol))
  52.     pol = reshape(pol,length(pol),1);
  53.     poldata = [real(pol(:,1)), imag(pol(:,1))];
  54.   endif
  55.  
  56.   ## determine continuous or discrete plane
  57.   vars = "sz";
  58.   varstr = vars(is_digital(sys) + 1);
  59.  
  60.   ## Plot the data
  61.   gset nologscale xy;
  62.   if(is_siso(sys))
  63.     title(sprintf("Pole-zero map from %s to %s", ...
  64.        sysgetsignals(sys,"in",1,1), sysgetsignals(sys,"out",1,1) ));
  65.   endif
  66.   xlabel(["Re(",varstr,")"]);
  67.   ylabel(["Im(",varstr,")"]);
  68.   grid;
  69.  
  70.   ## compute axis limits
  71.   axis(axis2dlim([zerdata;poldata]));
  72.   grid
  73.   ## finally, plot the data
  74.   if(length(zer) == 0)
  75.     plot(poldata(:,1), poldata(:,2),"@12 ;poles (no zeros);");
  76.   elseif(length(pol) == 0)
  77.     plot(zerdata(:,1), zerdata(:,2),"@31 ;zeros (no poles);");
  78.   else
  79.     plot(zerdata(:,1), zerdata(:,2),"@31 ;zeros;", ...
  80.       poldata(:,1), poldata(:,2),"@12 ;poles;");
  81.   endif
  82.   replot
  83.  
  84.   empty_list_elements_ok = save_emp;
  85.  
  86. endfunction
  87.