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

  1. function [magout,wn,z] = ddamp(a,Ts)
  2. %DDAMP    Natural frequency and damping factor for discrete systems.
  3. %    [MAG,Wn,Z] = DDAMP(A,Ts) returns vectors MAG, Wn and Z containing
  4. %    the z-plane magnitude, and the equivalent s-plane natural 
  5. %    frequency and damping factors of A.  Ts is the sample time.  The
  6. %    variable A can be in one of several formats:
  7. %        1) If A is square, it is assumed to be the state-space
  8. %           "A" matrix.
  9. %        2) If A is a row vector, it is assumed to be a vector of
  10. %           the polynomial coefficients from a transfer function.
  11. %        3) If A is a column vector, it is assumed to contain
  12. %           root locations.
  13. %
  14. %    Without the sample time, DDAMP(A) returns the magnitude only.  
  15. %    When invoked without left hand arguments DDAMP prints the 
  16. %    eigenvalues with their magnitude, natural frequency and damping
  17. %    factor in a tabular format on the screen.
  18. %
  19. %    For a discrete system eigenvalue, lambda, the equivalent s-plane
  20. %    natural frequency and damping ratio are
  21. %
  22. %        Wn = abs(log(lamba))/Ts    Z = -cos(angle(log(lamba)))
  23. %
  24. %    See also: EIG and DAMP.
  25.  
  26. %    Clay M. Thompson  7-23-90
  27. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  28.  
  29. error(nargchk(1,2,nargin));
  30.  
  31. [m,n] = size(a);
  32. if (m == n)
  33.     r = dsort(eig(a));
  34. elseif (m == 1)
  35.     r = dsort(roots(a));
  36. elseif (n == 1)
  37.     r = a;
  38. else
  39.     error('Must be a vector or a square matrix.');
  40. end
  41. mag = abs(r);
  42.  
  43. if nargin==2,    % If sample time is given solve for equivalent s-plane roots
  44.   s = log(r)/Ts;
  45.   wn = abs(s);
  46.   z = -cos(atan2(imag(s),real(s)));
  47. else
  48.   s = [];
  49.   wn = [];
  50.   z = [];
  51. end
  52.  
  53. if nargout==0,        % Print results on the screen.
  54.   disp('')
  55.   if nargin==2,
  56.     disp('   Eigenvalue        Magnitude      Equiv. Damping   Equiv. Freq. (rad/sec)')
  57.   else
  58.     disp('   Eigenvalue        Magnitude')
  59.   end
  60.   disp('')
  61.   disp([r,mag,z,wn])
  62.  
  63.   return % Suppress output
  64. end
  65. magout = mag; 
  66.