function out = threshlin(vec, th, mn, stp, gain)

%  function out = threshlin(vec, th, mn, stp, gain)
%
%  Linear output with threshold
%
%                   /  n
%                  /  i
%                 /  a
%                /  g
% output        /
%              |   <- stp
%              |
%  mn  ________|
%
%             th
%        input


if(nargin < 1)
  error('threshlin(): must supply a vector');
end;

if(nargin < 2)
  th = 0;
end;
if(nargin < 3)
  mn = 0;
end;
if(nargin < 4)
  stp = 0;
end;
if(nargin < 5)
  gain = 1;
end;

out = mn * ones(size(vec));
elems = find(vec > th);
if(~isempty(elems))
  out(elems) = stp + gain*vec(elems) - th;
end;


