Code covered by the BSD License

# stepfunc

### Marco Borges (view profile)

25 Jul 2013 (Updated )

Generates step-function signal and time vector where x is equal to 0 for n < 0 and 1 for x > 0.

stepfunc(n0,ini,fin)
```function [x,n] = stepfunc(n0,ini,fin)
% stepfunc - generates step-function signal and time vector where
% x is equal to 0 for n < 0 and 1 for x > 0. Unlike heaviside, x is equal
% to 0 instead of 0.5 for n = 0.
% Mathematical formula: x(n) = u(n-n0); n1 <= n,n0 <= n2
%
% Syntax:  [x,n] = stepfunc(n0, ini, fin)
%          [x,n] = stepfunc(n0, fin)
%
% Inputs:
%     n0 - step displacement
%    ini - initial time
%    fin - final time
%
% Outputs:
%      x - step function signal
%      n - signal time vector
%
% Example:
%     [x,n] = stepfunc(5,-10,10);
%     stem(n,x);
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%

% Author: Marco Borges, Ph.D. Student, Computer/Biomedical Engineer
% UFMG, PPGEE, Neurodinamica Lab, Brazil
% Website: http://www.cpdee.ufmg.br/
% July 2013; Version: v1; Last revision: 2013-07-24
% Changelog:
%
%------------------------------- BEGIN CODE -------------------------------
if nargin < 3
fin = ini;
ini = 0;
end

if ((n0 < ini) || (n0 > fin) || (ini > fin))
error('Arguments must satisfy n1 <= n0 <= n2')
end

n = ini:fin;
x = (n-n0) >= 0;
end
%-------------------------------- END CODE --------------------------------```