Remove linear trends
y = detrend(x)
y = detrend(x,'constant')
y = detrend(x,'linear',bp)
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
x is a matrix,
the trend from each column.
y = detrend(x,'constant') removes
the mean value from vector
x or, if
a matrix, from each column of the matrix.
y = detrend(x,'linear',bp) removes
a continuous, piecewise linear trend from vector
x is a matrix, from each column of the matrix.
bp contains the indices of the breakpoints
between adjacent linear segments. The breakpoint between two segments
is defined as the data point that the two segments share.
detrend(x,'linear'), with no breakpoint vector
specified, is the same as
sig = [0 1 -2 1 0 1 -2 1 0]; % signal with no linear trend trend = [0 1 2 3 4 3 2 1 0]; % two-segment linear trend x = sig+trend; % signal with added trend y = detrend(x,'linear',5) % breakpoint at 5th element y = -0.0000 1.0000 -2.0000 1.0000 0.0000 1.0000 -2.0000 1.0000 -0.0000
Note that the breakpoint is specified to be the fifth element, which is the data point shared by the two segments.
detrend computes the least-squares fit
of a straight line (or composite line for piecewise linear trends)
to the data and subtracts the resulting function from the data. To
obtain the equation of the straight-line fit, use
Usage notes and limitations:
If supplied and not empty, the input argument
satisfy the following requirements:
Be sorted in ascending order.
Restrict elements to integers in the interval
n is the number of elements in
a column of input argument
X , or the number of
X is a row
Contain all unique values.
See Variable-Sizing Restrictions for Code Generation of Toolbox Functions (MATLAB Coder).
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).