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

  1. %function dsys = tustin(csys,T,prewarpf);
  2. %
  3. %   Perform a continuous (CSYS) to discrete (DSYS) conversion
  4. %   by the prewarped Tustin method.  T is the sample time
  5. %   (in seconds) and PREWARP is the prewarp frequency in
  6. %   rad/sec. If no prewarp frequency is specified, a standard
  7. %   bilinear transformation is performed.
  8. %
  9. %   See also: DTRSP and SAMHLD.
  10.  
  11. function dsys = tustin(csys,T,prewarpf);
  12. if nargin ~= 3 & nargin ~= 2,
  13.     disp('usage: dsys = tustin(csys,T,prewarpf)')
  14.     return
  15.     end
  16.  
  17. %       the bilinear case is obtained in the limit as the prewarp
  18. %       frequency goes to zero.  For this case substitute the
  19. %       scaling alpha rather than have matlab crash on a 0/0
  20. %       calculation.
  21. %
  22. if nargin == 3,
  23.     if prewarpf < -eps,
  24.         error(' negative prewarp frequency')
  25.         return
  26.     elseif prewarpf < eps,
  27.         alpha = 2/T;
  28.     else
  29.         alpha = prewarpf/tan(T*prewarpf/2);
  30.         end
  31. else
  32.     alpha = 2/T;
  33.     end
  34.  
  35. [type,ny,nu,nx] = minfo(csys);
  36. if type == 'cons'
  37.   dsys = csys;
  38. elseif type == 'syst'
  39.  
  40.   [a,b,c,d] = unpck(csys);
  41.  
  42.   invterm = inv(eye(nx) - (1/alpha)*a);
  43.  
  44.   dsys = zeros(nx+ny+1,nx+nu+1);
  45.   dsys(1:nx,1:nx) = (eye(nx) + (1/alpha)*a)*invterm;
  46.   dsys(1:nx,nx+1:nx+nu) = invterm*b*sqrt(2/alpha);
  47.   dsys(nx+1:nx+ny,1:nx) = sqrt(2/alpha)*c*invterm;
  48.   dsys(nx+1:nx+ny,nx+1:nx+nu) = c*invterm*b*(1/alpha) + d;
  49.  
  50.   dsys(nx+ny+1,nx+nu+1) = -inf;
  51.   dsys(1,nx+nu+1) = nx;
  52. else
  53.     error('Not a SYSTEM matrix')
  54.     return
  55.     end
  56. %
  57. % Copyright MUSYN INC 1991,  All Rights Reserved
  58.