function xc = sigclip(x, uc, lc)
% This function inputs signal X and clips all values exceeding UC
% to UC and all values below LC to LC. Values of X between
% UC and LC are passed to the ouput vector unchanged:
%
% xc = sigclip(x,uc,lc)
%
% Output vector XC is the same size as X with values outside
% the range [uc, lc] clipped to uc and lc. If upper clip is
% less than lower clip, the output is 0.
%
%
xc = x;
if uc < lc % the upper cutoff is less than lower, zero out the signal
xc = zeros(size(x));
else
% Find indecies of x greater than upper clip
k = find(x > uc);
% Assign those samples to uc
xc(k) = uc;
% Find indecies of x less that lower clip
k = find(x < lc);
% Assign those samples to lc
xc(k) = lc;
end