function varargout = stepz(f,varargin)
%STEPZ  DFILT object step response.
%   [S,T] = STEPZ(F) computes 100 samples of the step response
%   of the DFILT object F, and returns it in vector S.  The 
%   vector of time samples at which S is evaluated is returned
%   in vector T.
%
%   [H,T] = STEPZ(F,N) computes the first N samples of the step
%   response.
%
%   [H,T] = STEPZ(F,N,Fs) separates the time samples by T = 1/Fs.
%   Fs is assumed to be in Hz.
%
%   STEPZ(...) with no output arguments plots the step response.
%
%   See also DFILT/IMPZ, DFILT/FREQZ, DFILT/ZPLANE, DFILT/GRPDELAY.

%   Author(s): R. Losada
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.4 $  $Date: 2000/06/13 21:21:28 $ 

[b,a] = tf(f);

[N,Fs,xlbl] = parseoptargs(varargin{:});

% Form time vector
t = (0:N-1)./Fs;

% Form input vector
x = ones(size(t));

s = filter(b,a,x);

if nargout == 0,
    newplot;
    stem(t,s,'filled');
    xlabel(xlbl);
    ylabel('Step response');
else
    varargout = {s,t};
end


%---------------------------------------------------------------------------
function [N,Fs,xlbl] = parseoptargs(varargin);
%PARSEOPTARGS   Parse optional input arguments.

% Assign default values
N = 100;
Fs = 1;
xlbl = 'n (samples)';

if nargin > 0,
  N = varargin{1};
  
  if nargin > 1,
      Fs = varargin{2};
      xlbl = 'nT (seconds)';
  end
end

