function [yout,x,t] = step(a,b,c,d,iu,t)
%STEP  Step response of LTI systems.
%
%   STEP(SYS)  plots the step response of each input channel of
%   the LTI system SYS.  The time range and number of points are
%   chosen automatically.
%
%   STEP(SYS,TFINAL)  simulates the step response from t = 0 to the 
%   final time t = TFINAL.  For discrete-time systems with unspecified 
%   sampling time, TFINAL is interpreted as the number of samples.
%
%   STEP(SYS,T)  uses the user-supplied time vector T for simulation. 
%   For discrete-time systems, T should be of the form  Ti:Ts:Tf  
%   where Ts is the sample time of the system.  For continuous systems, 
%   T should be of the form  Ti:dt:Tf  where dt will become the sample 
%   time of a discrete approximation to the continuous system.
%
%   STEP(SYS1,SYS2,...,T)  plots the step response of multiple LTI
%   systems SYS1,SYS2,... on a single plot.  The time vector T is 
%   optional.  You can also specify a color, line style, and marker 
%   for each system, as in  step(sys1,'r',sys2,'y--',sys3,'gx').
%
%   When invoked with left-hand arguments,
%        [Y,T] = STEP(SYS,...) 
%   returns the output response Y and the time vector T used for 
%   simulation.  No plot is drawn on the screen.  If SYS has 
%   NU inputs and NY outputs, and LT=length(T), the array Y is 
%   LT-by-NY-by-NU  and Y(:,:,j) gives the step response of the 
%   j-th input channel.
%
%   For state-space systems, 
%        [Y,T,X] = STEP(SYS,...) 
%   also returns the state trajectory X which is an LT-by-NX-by-NU
%   array if SYS has NX states.
%
%   See also  INITIAL, IMPULSE, LSIM.

%       Extra notes on user-supplied T:  For continuous-time systems, the system is 
%       converted to discrete time with a sample time of dt=t(2)-t(1).  The time 
%       vector plotted is then t=t(1):dt:t(end).  

% Old help
%warning(['This calling syntax for ' mfilename ' will not be supported in the future.'])
%STEP   Step response of continuous-time linear systems.
%	STEP(A,B,C,D,IU)  plots the time response of the linear system:
%		.
%		x = Ax + Bu
%		y = Cx + Du
%	to a step applied to the input IU.  The time vector is auto-
%	matically determined.  STEP(A,B,C,D,IU,T) allows the specification
%	of a regularly spaced time vector T.
%
%	[Y,X] = STEP(A,B,C,D,IU,T) or [Y,X,T] = STEP(A,B,C,D,IU) returns
%	the output and state time response in the matrices Y and X 
%	respectively.  No plot is drawn on the screen.  The matrix Y has 
%	as many columns as there are outputs, and LENGTH(T) rows.  The 
%	matrix X has as many columns as there are states.  If the time 
%	vector is not specified, then the automatically determined time 
%	vector is returned in T.
%
%	[Y,X] = STEP(NUM,DEN,T) or [Y,X,T] = STEP(NUM,DEN) calculates the 
%	step response from the transfer function description 
%	G(s) = NUM(s)/DEN(s) where NUM and DEN contain the polynomial 
%	coefficients in descending powers of s.
%
%	See also: INITIAL, IMPULSE, LSIM and DSTEP.

%	J.N. Little 4-21-85
%	Revised A.C.W.Grace 9-7-89, 5-21-92
%	Revised A. Potvin 12-1-95
%	Copyright (c) 1986-97 by The MathWorks, Inc.
%	$Revision: 1.9 $  $Date: 1997/04/09 00:45:38 $

ni = nargin;
no = nargout;
if ni==0,
   eval('exresp(''step'')')
   return
end
error(nargchk(2,6,ni));

% Determine which syntax is being used
switch ni
case 2
   if size(a,1)>1,
      % SIMO syntax
      a = num2cell(a,2);
      den = b;
      b = cell(size(a,1),1);
      b(:) = {den};
   end
   sys = tf(a,b);
   t = [];

case 3
   % Transfer function form with time vector
   if size(a,1)>1,
      % SIMO syntax
      a = num2cell(a,2);
      den = b;
      b = cell(size(a,1),1);
      b(:) = {den};
   end
   sys = tf(a,b);
   t = c;

case 4
   % State space system without iu or time vector
   sys = ss(a,b,c,d);
   t = [];

otherwise
   % State space system with iu 
   if min(size(iu))>1,
      error('IU must be a vector.');
   elseif isempty(iu),
      iu = 1:size(d,2);
   end
   sys = ss(a,b(:,iu),c,d(:,iu));
   if ni<6, 
      t = [];
   end
end

if no==1,
   yout = step(sys,t);
   yout = yout(:,:);
elseif no>1,
   [yout,t,x] = step(sys,t);
   yout = yout(:,:);
   x = x(:,:);
   t = t';
else
   step(sys,t);
end

% end step
