home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / TF2SS.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.0 KB  |  80 lines

  1. function [a,b,c,d] = tf2ss(num, den)
  2. %TF2SS    Transfer function to state-space conversion.
  3. %    [A,B,C,D] = TF2SS(NUM,DEN)  calculates the state-space 
  4. %    representation:
  5. %        .
  6. %        x = Ax + Bu
  7. %        y = Cx + Du
  8. %
  9. %    of the system:
  10. %                NUM(s) 
  11. %        H(s) = --------
  12. %                DEN(s)
  13. %
  14. %    from a single input.  Vector DEN must contain the coefficients of
  15. %    the denominator in descending powers of s.  Matrix NUM must 
  16. %    contain the numerator coefficients with as many rows as there are
  17. %    outputs y.  The A,B,C,D matrices are returned in controller 
  18. %    canonical form.  This calculation also works for discrete systems.
  19. %    To avoid confusion when using this function with discrete systems,
  20. %    always use a numerator polynomial that has been padded with zeros
  21. %    to make it the same length as the denominator.  See the User's
  22. %    guide for more details.
  23. %
  24. %    See also: SS2TF.
  25.  
  26. %     J.N. Little 3-24-85
  27. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  28. %    Latest revision 4-29-89 JNL
  29.  
  30. [mnum,nnum] = size(num);
  31. [mden,n] = size(den);
  32. % Check for null systems
  33. if  (n == 0 & nnum == 0), a=[]; b=[]; c=[]; d=[]; return, end
  34.  
  35. % Strip leading zeros from denominator
  36. inz = find(den ~= 0);
  37. den = den(inz(1):n);
  38. [mden,n] = size(den);
  39.  
  40. % Check for proper numerator
  41. if nnum > n
  42.     % Try to strip leading zeros to make proper
  43.     if (all(all(num(:,1:(nnum-n)) == 0)))
  44.         num = num(:,(nnum-n+1):nnum);
  45.         [mnum,nnum] = size(num);
  46.     else
  47.         error('Denominator must be higher or equal order than numerator.');
  48.     end
  49. end
  50.  
  51. % Pad numerator with leading zeros, to make it have the same number of
  52. % columns as the denominator, and normalize it to den(1)
  53. num = [zeros(mnum,n-nnum) num]./den(1);
  54.  
  55. % Do the D-matrix first
  56. if length(num)
  57.     d = num(:,1);
  58. else
  59.     d = [];
  60. end
  61.  
  62. % Handle special constant case:
  63. if n == 1
  64.     a = [];
  65.     b = [];
  66.     c = [];
  67.     return
  68. end
  69.  
  70. % Now do the rest, starting by normalizing den to den(1),
  71. den = den(2:n) ./ den(1);
  72. a = [-den; eye(n-2,n-1)];
  73. b = eye(n-1,1);
  74. if mnum > 0
  75.     c = num(:,2:n) - num(:,1) * den;
  76. else
  77.     c = [];
  78. end
  79.  
  80.