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

  1. function [a,b,c,d] = tfm2ss(Z1,Z2,Z3,Z4)
  2. % [SS_] = TFM2SS(TFM) or
  3. % [A,B,C,D] = TFM2SS(NUM,DEN,M,N) produces a state space Block Controller
  4. % (or Observer) form of a Proper Rational Transfer Function Matrix (MIMO)
  5. %
  6. %                   |N11(s) N12(s) .... N1m(s)|
  7. %     TFM  = 1/d(s) | ........................| = mksys(num,den,m,n,'tfm');
  8. %                   |Nn1(s) ........... Nnm(s)|
  9. %          
  10. %     NUM : a matrix whose rows are the coefficients of the numerators 
  11. %           of the TF matrix entries (ie : n11-->row1, n21-->row2, ..etc.).
  12. %     DEN : a row vector contains the coefficients of Characteristic 
  13. %           polynomial d(s) (with the highest degree: r).
  14. %     M   : no. of system inputs.
  15. %     N   : no. of system outputs.
  16. %
  17. %     Note: The resulting A matrix will have "r x min(m,n)" states 
  18. %           which is nonminimal. The regular state-space can be recovered
  19. %           "branch".
  20.  
  21. % R. Y. Chiang & M. G. Safonov 10/22/88
  22. % Copyright (c) 1988 by the MathWorks, Inc.
  23. % All Rights Reserved.
  24. %---------------------------------------------------------------------
  25.  
  26. inargs = '(num,den,m,n)';
  27. eval(mkargs(inargs,nargin,'tfm'))
  28.  
  29. %
  30. % ------ Convert to Block Observer Form
  31. %        (if there are more inputs than outputs):
  32. %
  33. m0 = m; n0 = n;
  34. if m0 > n0
  35.     m = n0; n = m0;
  36. end
  37. %
  38. num = num./den(1);
  39. den = den./den(1);
  40. [rd,cd] = size(den);
  41. rm = (cd-1) * m;
  42. [rn,cn] = size(num);
  43. %
  44. if cn < cd
  45.    num = [zeros(rn,(cd-cn)) num];
  46. end
  47. %
  48. % ------ State Space of a Constant :
  49. %
  50. if cd == 1
  51.    a = []; b = 0; c = 0; d = num;
  52.    return
  53. end
  54. %
  55. % ------ D matrix :
  56. %
  57. d = zeros(n,m);
  58. d(:)  = num(:,1);
  59. %
  60. % ------ Proper Rational TF matrix --> Strictly proper :
  61. %
  62. for v = 1:m*n
  63.     nnum(v,:) = num(v,:) - den * num(v,1);
  64. end
  65. %
  66. % ------ A matrix :
  67. %
  68. for i = 1:cd-1
  69.     a1(1:m,i*m-(m-1):i*m) = -den(i+1) * eye(m);
  70.   end
  71. if rm == m
  72.     a = a1;
  73. else
  74.     a = [a1;eye(rm-m) zeros(rm-m,m)];
  75. end
  76. %
  77. % ------ B matrix :
  78. %
  79. if rm == m
  80.     b = eye(m);
  81. else
  82.     b = [eye(m);zeros(rm-m,m)];
  83. end
  84. %
  85. % ------ C matrix :
  86. %
  87. u = 0.;
  88. for s = 1:cd-1
  89.     for p = 1 : m
  90.         u = u+1;
  91.         c(:,u) = nnum(p*n-(n-1):p*n,s+1);
  92.     end
  93. end
  94. %
  95. % ------ Convert to Block Observer Form 
  96. %        (if there are more inputs than outputs):
  97. %
  98. if m0 > n0
  99.    a = a'; btemp = b; b = c'; c = btemp';
  100.  end
  101. %
  102. if xsflag
  103.    a = mksys(a,b,c,d);
  104. end
  105. %
  106. % ------ End of TFM2SS.M ---- RYC/MGS %
  107.