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

  1. function [yout,x,t] = step(a,b,c,d,iu,t)
  2. %STEP    Step response of continuous-time linear systems.
  3. %    STEP(A,B,C,D,IU)  plots the time response of the linear system:
  4. %        .
  5. %        x = Ax + Bu
  6. %        y = Cx + Du
  7. %    to a step applied to the input IU.  The time vector is auto-
  8. %    matically determined.  STEP(A,B,C,D,IU,T) allows the specification
  9. %    of a regularly spaced time vector T.
  10. %
  11. %    [Y,X] = STEP(A,B,C,D,IU,T) or [Y.X,T] = STEP(A,B,C,D,IU) returns
  12. %    the output and state time response in the matrices Y and X 
  13. %    respectively.  No plot is drawn on the screen.  The matrix Y has 
  14. %    as many columns as there are outputs, and LENGTH(T) rows.  The 
  15. %    matrix X has as many columns as there are states.  If the time 
  16. %    vector is not specified, then the automatically determined time 
  17. %    vector is returned in T.
  18. %
  19. %    [Y,X] = STEP(NUM,DEN,T) or [Y,X,T] = STEP(NUM,DEN) calculates the 
  20. %    step response from the transfer function description 
  21. %    G(s) = NUM(s)/DEN(s) where NUM and DEN contain the polynomial 
  22. %    coefficients in descending powers of s.
  23. %
  24. %    See also: INITIAL, IMPULSE, LSIM and DSTEP.
  25.  
  26. %    J.N. Little 4-21-85
  27. %    Revised A.C.W.Grace 9-7-89, 5-21-92
  28. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  29.  
  30. nargs = nargin;
  31. if nargs==0, eval('exresp(''step'')'), 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.     [a,b,c,d] = tf2ss(num,den);
  39.     iu = 1;
  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, x = []; t = []; if nargout~=0, yout=[]; end, return, end
  47.  
  48. if nargs>4 
  49.     if ~isempty(b), b=b(:,iu); end
  50.     d=d(:,iu);
  51. end
  52.  
  53. % Workout time vector if not supplied.
  54. if (nargs==5 | nargs==4),
  55.   if isempty(a),
  56.     t = 0:.1:1;
  57.   else
  58.     % The next two constants control the precision of the plot
  59.     % and the time interval of the plot.
  60.     st=0.005; % Set settling time bound  = 0.5%
  61.     precision=30; % Show approx 30 points for simple graph
  62.     % Step response is effectively equal to placing initial conditions
  63.     % on the plant as follows:
  64.     [n,m]=size(b);
  65.     if abs(rcond(a)) > eps
  66.         x0 = -a\(b*ones(m,1));
  67.     % Cater for pure integrator case
  68.     else
  69.         x0 = ones(n,1);
  70.     end
  71.     t=timvec(a,b,c,x0,st,precision);
  72.   end
  73. end
  74.  
  75.  
  76. %  Multivariable systems
  77. if nargs==4
  78.         [iu,nargs,y]=mulresp('step',a,b,c,d,t,nargout,0);
  79.         if ~iu, if nargout, yout = y; end, return, end
  80. end
  81.  
  82.  
  83. % Simulation
  84. dt = t(2)-t(1);
  85. [aa,bb] = c2d(a,b,dt);
  86. n = length(t);
  87. [nb,mb] = size(b);
  88. x = ltitr(aa,bb,ones(n,1),zeros(nb,mb));
  89. if isempty(a),
  90.   x = [];
  91.   y = ones(n,1)*d.';
  92. else
  93.   y=x*c.'+ ones(n,1)*d.';
  94. end
  95. if nargout==0,        % If no output arguments, plot graph
  96.     dcgain = 0;
  97.     if abs(rcond(a)) > eps
  98.         dcgain=-c/a*b+d;
  99.     end
  100.         plot(t,y,[0,t(length(t))],[dcgain';dcgain'],':')
  101.         xlabel('Time (secs)'), ylabel('Amplitude')
  102.  
  103.         return % Suppress output
  104. end
  105. yout = y; 
  106.