Detrend (FPScript)

21.09.2021

Removes a constant, linear or adaptive trend from a data set.

Syntax

Detrend(Signal, [ Mode = DETREND_CONSTANT ] [ , Parameter = 0 ])

 

The syntax of the Detrend function consists of the following parts:

Part

Description

Signal

The data set with the trend you want to remove.

All data structures are allowed, except scalar value und list. All numeric data types are permitted.

For complex data types the absolute value is formed.

If the argument is a list, then the function is executed for each element of the list and the result is also a list.

Mode

Specifies whether a constant, linear or adaptive trend is to be subtracted. If you omit the argument, a constant trend is subtracted.

The argument Mode can have the following values:

Constant

Meaning

DETREND_CONSTANT

Subtracts the mean value.

DETREND_LINEAR

Subtracts the best straight line, i.e. the straight line for which the sum of squares of the deviations to the signal is minimal.

DETREND_ADAPTIVE

Subtracts the mean value of the upper and lower envelope.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

If this argument is omitted, it will be set to the default value DETREND_CONSTANT.

Parameter

Controls the algorithm for the calculation of the adaptive trend. If positive and specified without a unit, it specifies the number N of neighbors to be taken into account when determining the next relevant sampling point. If negative or specified with the unit "%", it specifies the hysteresis as a percentage of the span of the data set with which local maxima are searched to determine N automatically. If you omit the argument or pass 0, this corresponds to an hysteresis of 5%.

Permitted data structures are scalar value. All numeric data types are permitted.

For complex data types the absolute value is formed.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

If this argument is omitted, it will be set to the default value 0.

Remarks

The result has the same structure and unit as the argument Signal.

For aggregate data structures, only the Y component is considered and the X or, if applicable, Z component is copied into the result without modification. For data matrices and signal series, the calculation is carried out for each column or each signal therein. The calendar time and time span data types remain in the result. For all other numerical data types, the result is of a 64-bit floating point value.

When determining the constant or linear trend, the mean value of the signal is first calculated and then a search begins for the first and last level crossing using this value. If two level crossings were found, the mean value or the best straight line is calculated only for the range between these two level crossings. This prevents errors that occur at the end of the data set via the phase cut-off of the periodic signals. If no level crossings were found, then all values are included in the calculation.

For calculating the adaptive trend, the upper and lower envelope of the signal are calculated with the same algorithm, which is also used by the UpperEnvelope and LowerEnvelope functions. These envelopes are then sampled using linear interpolation for all X values of the data set. The arithmetic mean is then formed from these two envelopes. The trend thus obtained is subtracted from the original data.

Available in

FlexPro Basic, Professional, Developer Suite

Examples

Detrend(Signal)

Corresponds to Signal - Trend(Signal).

Integral(Detrend(Signal, DETREND_LINEAR))

Removes a linear trend from the signal before integration.

Detrend(Signal, DETREND_ADAPTIVE, 2%)

Removes an adaptive trend from the signal. The number of neighbors for searching the sampling points of envelopes is determined using the local maxima in the signal, which are searched using an hysteresis of 2%.

DCRemovalFilter(DataSet)

Removes the offset of a data set including neighboring frequencies) with the help of the DCRemovalFilter function (high-pass filter).

See Also

UpperEnvelope Function

LowerEnvelope Function

Trend Function

DCRemovalFilter Function

Share article or send as email:

You might be interested in these articles