This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Subtract offset or trend from data signals


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


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.


Subtract Mean Values From Signals

Load the data.

load dryer2 
data = iddata(y2,u2,0.08);

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

[data_d,T] = detrend(data,0);

Note that the detrended data has zero mean value.

Remove Offsets From Data

Remove specified offset from input and output signals.

Load SISO data containing vectors u2 and y2.

load dryer2

Create a data object with sample time of 0.08 seconds and plot it.

data = iddata(y2,u2,0.08);

The data has a nonzero mean value.

Store the data offset and trend information in a TrendInfo object.

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 the detrended data on the same plot.

hold on

View the mean value removed from the data.

ans = 

  struct with fields:

        DataName: 'data'
     InputOffset: 5
    OutputOffset: 5
      InputSlope: 0
     OutputSlope: 0

Subtract 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.

Subtract 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];

Introduced before R2006a

Was this topic helpful?