home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / ss2tf.m < prev    next >
Text File  |  1999-04-29  |  2KB  |  74 lines

  1. # Copyright (C) 1996 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 [num,den] = ss2tf(a,b,c,d)
  18. # [num,den] = ss2tf(a,b,c,d)
  19. # Conversion from tranfer function to state-space.
  20. # The state space system
  21. #      . 
  22. #      x = Ax + Bu
  23. #      y = Cx + Du
  24. #
  25. # is converted to a transfer function
  26. #
  27. #                num(s)
  28. #          G(s)=-------
  29. #                den(s)
  30. #
  31. # used internally in system data structure manipulations
  32.  
  33. # Written by R. Bruce Tenison (June 24, 1994) btenison@eng.auburn.edu
  34. # a s hodel: modified to allow for pure gain blocks Aug 1996
  35.  
  36. # Check args
  37.   [n,m,p] = abcddim(a,b,c,d);
  38.   if (n == -1)
  39.     num = [];
  40.     den = [];
  41.     error("ss2tf: Non compatible matrix arguments");
  42.   elseif ( (m != 1) | (p != 1))
  43.     num = [];
  44.     den = [];
  45.     error(["ss2tf: not SISO system: m=",num2str(m)," p=",num2str(p)]);
  46.   endif
  47.   
  48.   if(n == 0)
  49.     # gain block only
  50.     num = d;
  51.     den = 1;
  52.   else
  53.     # First, get the denominator coefficients
  54.     den = poly(a);
  55.   
  56.     # Get the zeros of the system
  57.     [zz,g] = tzero(a,b,c,d);
  58.  
  59.     # Form the Numerator (and include the gain)
  60.     if (!isempty(zz))
  61.       num = g * poly(zz);
  62.     else
  63.       num = g;
  64.     endif
  65.   
  66.     # the coefficients must be real
  67.     den = real(den);
  68.     num = real(num);
  69.   endif
  70. endfunction
  71.  
  72.