home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / zp2tf.m < prev    next >
Encoding:
Text File  |  1999-12-18  |  2.6 KB  |  74 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{num}, @var{den}] =} zp2tf (@var{zer}, @var{pol}, @var{k})
  21. ##  Converts zeros / poles to a transfer function.
  22. ## @strong{Inputs}
  23. ## @table @var
  24. ## @item zer, pol
  25. ## vectors of (possibly complex) poles and zeros of a transfer
  26. ## function.  Complex values should appear in conjugate pairs
  27. ## @item k
  28. ## real scalar (leading coefficient)
  29. ## @end table
  30. ## @code{[num,den] = zp2tf(zer,pol,k)} forms the transfer function 
  31. ## @code{num/den} from the vectors of poles and zeros.
  32. ## @end deftypefn
  33.  
  34. function [num, den] = zp2tf (zer, pol, k)
  35.  
  36.   ## Find out whether data was entered as a row or a column vector and
  37.   ## convert to a column vector if necessary
  38.   ## Written by A. S. Hodel with help from students Ingram, McGowan.
  39.   ## a.s.hodel@eng.auburn.edu
  40.  
  41.   [rp,cp] = size(pol);
  42.   [rz,cz] = size(zer);
  43.  
  44.   if(!(is_vector(zer) | isempty(zer)) )
  45.     error(sprintf("zer(%dx%d) must be a vector",rz,cz));
  46.   elseif(!(is_vector(pol) | isempty(pol)) )
  47.     error(sprintf("pol(%dx%d) must be a vector",rp,cp));
  48.   elseif(length(zer) > length(pol))
  49.     error(sprintf("zer(%dx%d) longer than pol(%dx%d)",rz,cz,rp,cp));
  50.   endif
  51.  
  52.   ## initialize converted polynomials
  53.  
  54.   num = k;  den = 1;
  55.  
  56.   ## call zp2ssg2 if there are complex conjugate pairs left, otherwise
  57.   ## construct real zeros one by one.  Repeat for poles.
  58.  
  59.   while(!isempty(zer))
  60.     if( max(abs(imag(zer))) )     [poly,zer] = zp2ssg2(zer);
  61.     else                          poly = [1, -zer(1)];  
  62.                                   zer = zer(2:length(zer));      endif
  63.     num = conv(num,poly);
  64.   endwhile
  65.  
  66.   while(!isempty(pol))
  67.     if( max(abs(imag(pol))) )     [poly,pol] = zp2ssg2(pol);
  68.     else                          poly = [1, -pol(1)];  
  69.                                   pol = pol(2:length(pol));      endif
  70.     den = conv(den,poly);
  71.   endwhile
  72.  
  73. endfunction
  74.