Documentation Center

  • Trial Software
  • Product Updates

detrend

Subtract offset or trend from data signals

Syntax

data_d = detrend(data)
data_d = detrend(data,Type)
[data_d,T] = detrend(data,Type)
data_d = detrend(data,1,brkp)

Description

data_d = detrend(data) subtracts the mean value from each time-domain or time-series signal data. data_d and data are iddata objects.

data_d = detrend(data,Type) subtracts a mean value from each signal when Type = 0, a linear trend (least-squares fit) when Type = 1, or a trend specified by a TrendInfo object when Type = T.

[data_d,T] = detrend(data,Type) stores the trend information as a TrendInfo object T.

data_d = detrend(data,1,brkp) subtracts a piecewise linear trend at one or more breakpoints brkp. brkp is a data index where discontinuities between successive linear trends occur. When brkp contains breakpoints that match the time vector, detrend subtracts a continuous piecewise linear trend. You cannot store piecewise linear trend information as an output argument.

Examples

Substract Mean Values From Signals

Subtract mean values from input and output signals and store the trend information.

load dryer2
data = iddata(y2,u2,0.08);
plot(data);
[data_d,T] = detrend(data,0);
hold on
plot(data_d)

Remove Offsets From Signals

Remove specified offset from input and output signals:

% Load SISO data containing vectors u2 and y2.
load dryer2
% Create data object with sampling time of 0.08 sec.
data=iddata(y2,u2,0.08)
plot(data)
% Create a TrendInfo object for storing offsets and trends.
T = getTrend(data)
% Assign offset values to the TrendInfo object.
T.InputOffset=5;
T.OutputOffset=5;
% Subtract offset from the data.
data_d = detrend(data,T)
% Plot detrended data on the same plot.
hold on
plot(data_d)

Substract Several Linear Trends

Subtract several linear trends that connect at three breakpoints [30 60 90]:

data = detrend(data,1,[30 60 90]);
% [30 60 90] are data indexes where breakpoints occur.

Substract Mean Value and a V-shaped Trend

Subtract a mean value from the input signal and a V-shaped trend from the output signal, such that the V peak occurs at the breakpoint value of 119:

zd1 = z(:,:,[]); zd2 = z(:,[],:);
zd1(:,1,[]) = detrend(z(:,1,[]),1,119);
zd2(:,[],1) = detrend(z(:,[],1));
zd = [zd1,zd2];

See Also

|

Was this topic helpful?