Skip to content

sidDetrend

Python equivalent: sid.detrend

Remove polynomial trend from time-domain data.

x_dt = sidDetrend(x)
x_dt = sidDetrend(x, 'Order', d)
[x_dt, trend] = sidDetrend(x, 'SegmentLength', L)

Removes a polynomial trend of degree d from each channel of x. Detrending is standard preprocessing before spectral estimation: unremoved trends bias low-frequency spectral estimates and violate stationarity assumptions.

Inputs

Name Description
x (N x n_ch) or (N x n_ch x L) real data matrix. Vectors are
treated as single-channel column data.

Name-value options

Name Description
'Order' Polynomial degree to remove (default: 1).
0 = remove mean, 1 = linear, 2 = quadratic, etc.
'SegmentLength' Detrend each non-overlapping segment independently
(default: N, i.e., full record).

Outputs

Name Description
x_detrended (N x n_ch) or (N x n_ch x L), same size as input
trend (N x n_ch) or (N x n_ch x L), the removed trend
(x = x_detrended + trend)

Examples

y_dt = sidDetrend(y);                    % remove linear trend
y_dm = sidDetrend(y, 'Order', 0);        % remove mean only
[y_dt, trend] = sidDetrend(y);           % also get the trend
y_ds = sidDetrend(y, 'SegmentLength', 500); % segment-wise
% Typical workflow
y_dt = sidDetrend(y);
u_dt = sidDetrend(u);
result = sidFreqBT(y_dt, u_dt);

Specification

(Data preprocessing — not yet in SPEC.md)

See also

sidFreqBT, sidFreqETFE, sidFreqMap

Changelog

  • 2026-03-29: First version by Pedro Lourenço.