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

  1. function thd=thc2thd(thc,T)
  2. %THC2THD  Converts a continuous time model to discrete time    
  3. %
  4. %    THD = thc2thd(THC,T)
  5. %    
  6. %    THC: The continuous time model, specified in THETA format 
  7. %        (See help theta)
  8. %    T: The sampling interval
  9. %    THD: The discrete time model, in THETA format
  10. %
  11. %    Note that the covariance matrix is not translated to discrete time
  12. %    for input-output type models
  13. %
  14. %    See also THD2THC.
  15.  
  16. %    L. Ljung 10-2-90
  17. %    Copyright (c) 1990 by the MathWorks, Inc.
  18. %    All Rights Reserved.
  19.  
  20. Told=gett(thc);
  21. if nargin<2,error('The sampling time T must be specified!'),end
  22. if Told>0,error('This model is already denoted as discrete-time!'),end
  23. if T<0,error('The sampling interval must be positive!'),end
  24. lamscale=abs(Told)/T;
  25. [nrth,ncth]=size(thc);[p,covp,lam]=th2par(thc);nnd=length(p);nu=thc(1,3);
  26. if isthss(thc),rarg=thc(1,6);ny=thc(1,4);
  27. thd=thc; thd(1,2)=T;
  28. thd(4+nnd+rarg:nrth,1:ny)=lamscale*lam;
  29. thd(1:2,1)=lamscale^ny*thc(1:2,1);
  30. return,end 
  31. if nrth>3+nnd,delays=thc(nrth,1:nu);else delays=zeros(1,nu);end
  32.  
  33. nnk=[round(delays/T) 0];
  34. [a,b,c,d,k]=th2ss(thc);nu=thc(1,3);
  35. [m,n] = size(a);
  36. [m,nb] = size(b);
  37. [m,nk] = size(k);
  38.  
  39. s = expm([[a b k]*T; zeros(nb+nk,n+nb+nk)]);
  40. a = s(1:n,1:n);
  41. bk = s(1:n,n+1:n+nb+nk);
  42. dk = [d 1];
  43.  
  44. den = poly(a);
  45.  
  46. [mc,nc] = size(c);
  47. for iu=1:nu+1
  48. b1 = bk(:,iu);
  49. d1 = dk(:,iu);
  50.  
  51.     num1 = poly(a-b1*c) + (d1 - 1) * den;
  52.     num(iu,1:length(num1)+nnk(iu))=[zeros(1,nnk(iu)) num1];
  53. end
  54.  
  55. thd=poly2th(den,num(1:nu,:),num(nu+1,:),1,ones(nu,1),lamscale*lam,T);
  56. thd(2,1)=thc(2,1)*lamscale;
  57. end