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

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