Signal Processing Toolbox | Help Desk |
detrend
Remove linear trends.
y = detrend(x) y = detrend(x,0)
detrend
removes the mean value or linear trend from a vector or matrix, usually for FFT processing.
y = detrend(x)
removes the best straight-line fit from vector x
and returns it in y
. If x
is an array, detrend
removes the trend from each column.
y = detrend(x,0)
removes the mean value from vector x
or, if x
is an array, from each column of the array.
detrend
computes the least-squares fit of a straight line to the data and subtracts the resulting function from the data. The main part of the algorithm is
m = length(x);
a = [(1:m)'/m ones(m,1)];
y = x - a*
(a\x);
To obtain the equation of the straight-line fit, use polyfit
.