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

  1. function [num,den]=th2tf(th,iu)
  2. %TH2TF    Transforms from the THETA-format to transfer functions
  3. %
  4. %    [NUM,DEN] = th2tf(TH,IU)
  5. %
  6. %    TH: The model, defined in the THETA-format (See help theta)
  7. %    IU: The input number (default 1) to be considered. Noise source
  8. %           number ni is counted as input number -ni.
  9. %    NUM: The numerator(s) of the transfer function. For a multivariable
  10. %         model row k of NUM gives the transfer function from input # IU
  11. %         to output # k.
  12. %    DEN: The denominator of the transfer function. (Common to all outputs)
  13. %
  14. %    NUM and DEN are given in the standard formats of the Control Systems
  15. %    Toolbox (both for continuous and discrete time models)
  16.  
  17. %    L. Ljung 10-2-90
  18. %    Copyright (c) 1990 by the MathWorks, Inc.
  19. %    All Rights Reserved.
  20. nu=th(1,3);
  21. if nargin<2,if nu>0,iu=1;else iu=-1;end,end;if iu==0,iu=-1;end
  22. if iu>nu,error('There are not that many inputs in the system'),end
  23. if isthss(th), 
  24.     [a,b,c,d,k]=th2ss(th);    
  25.     [mc,nc] = size(c);dk=eye(mc);
  26.     den = poly(a);
  27.     if iu>0,b = b(:,iu);d=d(:,iu);
  28.     else b=k(:,-iu);d=dk(:,-iu);end
  29.     
  30.     num = ones(mc, nc+1);
  31.     for i=1:mc
  32.         num(i,:) = poly(a-b*c(i,:)) + (d(i) - 1) * den;
  33.         nnd(i)=max(find(abs(num(i,:))>eps));
  34.     end
  35.  
  36. nd=max(find(abs(den)>eps));ord=max([nd nnd]);
  37. den=den(1:ord);num=num(:,1:ord);
  38.  
  39. return,end
  40. nu=th(1,3);na=th(1,4);
  41. if nu>0,nb=th(1,5:4+nu);end
  42. nc=th(1,5+nu);,nd=th(1,6+nu);
  43. if nu>0,nf=th(1,7+nu:6+2*nu);,nk=th(1,7+2*nu:6+3*nu);,end
  44.  
  45. [a,b,c,d,f]=th2poly(th);T=th(1,2);
  46. if iu>0,den=conv(a,f(iu,1:nf(iu)+1));else den=conv(a,d);end
  47. if iu>0,num=b(iu,1:nb(iu)+nk(iu));else num=c;end
  48. ld=length(den);ln=length(num);mn=max(ld,ln);
  49. if T>0,den=[den,zeros(1,mn-ld)];num=[num,zeros(1,mn-ln)];
  50. else den=[zeros(1,mn-ld),den];num=[zeros(1,mn-ln),num];end
  51.