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

  1. function [yout,x,t] = impulse(a,b,c,d,iu,t)
  2. %IMPULSE Impulse response of continuous-time linear systems.
  3. %     IMPULSE(A,B,C,D,IU)  plots the time response of the linear system
  4. %        .
  5. %        x = Ax + Bu
  6. %        y = Cx + Du
  7. %    to an impulse applied to the single input IU.  The time vector is
  8. %    automatically determined.  
  9. %
  10. %    IMPULSE(NUM,DEN) plots the impulse response of the polynomial 
  11. %    transfer function  G(s) = NUM(s)/DEN(s)  where NUM and DEN contain
  12. %    the polynomial coefficients in descending powers of s.
  13. %
  14. %    IMPULSE(A,B,C,D,IU,T) or IMPULSE(NUM,DEN,T) uses the user-supplied
  15. %    time vector T which must be regularly spaced.  When invoked with
  16. %    left hand arguments,
  17. %        [Y,X,T] = IMPULSE(A,B,C,D,...)
  18. %        [Y,X,T] = IMPULSE(NUM,DEN,...)
  19. %    returns the output and state time history in the matrices Y and X.
  20. %    No plot is drawn on the screen.  Y has as many columns as there 
  21. %    are outputs and length(T) rows.  X has as many columns as there 
  22. %    are states.
  23. %
  24. %    See also: STEP,INITIAL,LSIM and DIMPULSE.
  25.  
  26. %    J.N. Little 4-21-85
  27. %    Revised: 8-1-90  Clay M. Thompson, 2-20-92 ACWG
  28. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  29.  
  30. nargs = nargin;
  31. if nargs==0, eval('exresp(''impulse'')'), return, end
  32.  
  33. error(nargchk(2,6,nargs));
  34.  
  35. if (nargs < 4)     % Convert to state space
  36.     [num,den] = tfchk(a,b);
  37.     if nargs==3, t = c; end
  38.     iu = 1;
  39.     [a,b,c,d] = tf2ss(num,den);
  40.     nargs = nargs+3;
  41. else
  42.     error(abcdchk(a,b,c,d));
  43. end
  44.  
  45. [ny,nu] = size(d);
  46. if (nu*ny==0)|isempty(a),
  47.    x = []; t = []; if nargout~=0, yout=[]; end, return, 
  48. end
  49.  
  50. if nargs>4
  51.     if ~isempty(b),    b = b(:,iu); end
  52. end
  53.  
  54. % Workout time vector if not supplied.
  55. if nargs==5 | nargs==4
  56.  
  57. % The next three constants control the precision of the plot
  58. % and the time interval of the plot.
  59.         st=0.005; % Set settling time bound  = 0.5%
  60.         tint=1; % Set time interval to approx.  1*st% set. time
  61.         precision=30; % Show approx 30 points for simple graph
  62.  
  63.     m=min(size(b));
  64.     [n,m]=size(b);
  65.     if m>1, x0=max(abs(b.')).'; else, x0=b; end
  66.         t=timvec(a,b,c,x0,st,precision);
  67. end
  68.  
  69. %  Multivariable systems
  70. if nargs==4
  71.         [iu,nargs,y]=mulresp('impulse',a,b,c,d,t,nargout,0);
  72.     if ~iu, if nargout, yout = y; end, return, end
  73. end
  74.  
  75. dt = t(2)-t(1);
  76. [aa,bb] = c2d(a,b,dt);
  77. n = length(t);
  78. x = ltitr(aa,bb,zeros(n,1),b);
  79. y = x * c.';
  80.  
  81. % Plot Graph
  82. if nargout==0
  83.         plot(t,y,[t(1),t(length(t))],zeros(2,1),':')
  84.         xlabel('Time (secs)'), ylabel('Amplitude')
  85.     return % Suppress output
  86. end
  87. yout = y; 
  88.  
  89.  
  90.