Diff (FPScript)

21.09.2021

Calculates differences of neighboring Y values as well as right and left-sided difference quotients.

Syntax

Diff(DataSet [ , Mode = DIFF_FORWARD ])

 

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

Part

Description

DataSet

The data set from which the differences of neighboring Y values or different quotients are to be calculated.

Permitted data structures are data series, data matrix, signal, signal series und signal series with two-dimensional X-component. All numeric data types are permitted.

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

Determines the mode of the differences used.

The argument Mode can have the following values:

Constant

Meaning

DIFF_FORWARD

Uses forward (i.e. right-sided) differences D[n] = Y[n+1] -Y[n].

DIFF_QUOTIENT_FORWARD

Uses forward (i.e. right-sided) difference quotients D[n] = (Y[n+1] -Y[n]) / (X[n+1] - X[n]).

DIFF_BACKWARD

Uses backward (i.e. left-sided) differences D[n] = Y[n] -Y[n-1].

DIFF_QUOTIENT_BACKWARD

Uses backward (i.e. left-sided) difference quotients D[n] = (Y[n] -Y[n-1]) / (X[n] - X[n-1]).

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

Remarks

The result always has the data type 64-bit floating point.

For data matrices and signal series, the calculation takes place column by column. The values are converted to 64-bit floating points before the calculation is made. The X component, and thus the data set length of the result, is reduced by one compared to the input data set. If present, the X component is copied to the result unchanged.

Available in

FlexPro View, Basic, Professional, Developer Suite

Examples

Diff(Signal.X)

Calculates the differences of neighboring X values of a signal to calculate the sampling increments.

Diff(Signal)

Calculates the differences of neighboring Y values of a signal, e.g. for conversion of a step signal to an impulse signal.

Diff({1, 3.5, 5, 5.5, 4, 3})

Calculates the differences of neighboring values and produces {2.5, 1.5, 0.5, -1.5, -1} as the result. The data set length of the result is reduced by one compared to the input data set.

Diff(Signal, DIFF_QUOTIENT_FORWARD)

Calculates the forward (i.e. right-hand) difference quotients of neighboring data points of a signal.

Derivative(Signal)

Calculates the discrete derivative of a signal with the help of central difference quotients. The result thus provides greater accuracy when calculating the numerical derivative compared to the Diff function and has the same data set length as the input data set. For approximation of the derivative, the Derivative function should therefore be used instead of the Diff function.

See Also

Derivative Function

SavitzkyGolayDerivative Function

Integral Function

Signal Analysis - Analysis Object

Share article or send as email:

You might be interested in these articles