timeseries

Methods

Method Reference: timeseries.detrend

timeseries: ts = detrend (ts, type)

timeseries: ts = detrend (ts, type, ind)

Remove a polynomial trend from a series.

ts = detrend (ts, type) subtracts from each column of the data the polynomial fitted to it by least squares against Time: its mean for 'constant' or 0, a straight line for 'linear' or 1, and a polynomial of that degree for any larger integer. NaN values are left out of the fit and stay NaN. Every other property is kept.

ts = detrend (ts, type, ind) detrends only the columns ind of the data, or its rows where IsTimeFirst is false.

The data must be double or single, of two dimensions. MATLAB fits against the positions of the samples, closing up the gaps left by NaN, so its line is wrong where the time is not uniform or a value is missing; it also returns a series of fewer than three samples unchanged, where here 'constant' of [1 3] is [-1 1].

See also: timeseries.filter, timeseries.idealfilter

Source Code: timeseries

detrend removes the mean, or the best line, fitted against the times, so irregular times are handled correctly.

 ts = timeseries ([2; 3; 8; 13], [0; 1; 2; 6]);
 s = detrend (ts, 'linear');
 s.Data'
ans =

  -0.3253  -1.1807   1.9639  -0.4578
 s = detrend (ts, 'constant');
 s.Data'
ans =

  -4.5000  -3.5000   1.5000   6.5000