Derivative

Shippingstateful
derivative

Numerical differentiation with state persistence across blocks

Signature

Inputs

  • signalSignalrequired

Outputs

  • resultSignal

Parameters

KeyTypeDefaultNotes
methodenumcentralone of: central, 5point, second

Description

Derivative estimates the time derivative of an incoming signal by finite differences. It consumes a single signal input and emits a result of the same length, sample-aligned with the input. The finite-difference scheme is selected by the method parameter: central (second-order two-sided), 5point (fourth-order five-point stencil), or second (the second derivative ).

The node is stateful. Its DerivState carries the last sample value and its timestamp across processing blocks, so streaming DAQ data split into consecutive buffers is differentiated continuously without a discontinuity or a lost sample at every block boundary. The spacing is taken from the signal's time base, so non-uniform or per-block sample rates are handled through the stored timestamps rather than an assumed constant step.

Units propagate: differentiating a quantity of unit yields unit (e.g. m becomes m/s, and second method gives m/s^2). Because differentiation is a linear operation on samples, uncertainty (sigma) propagates through the stencil coefficients; note that finite differencing amplifies high-frequency noise, so output sigma is typically larger than input sigma. Consider pre-smoothing noisy inputs.

Mathematics

Examples

Velocity from a position track

Feed a position signal in metres into Derivative with method = central. The output carries unit m/s. For a track sampled at 1 kHz (), a linear ramp of over yields a flat output at , and the stored DerivState makes the estimate seamless across buffer boundaries in a live acquisition.

Acceleration in one node

Set method = second to obtain directly from a position signal instead of chaining two Derivative nodes. Input unit m produces output unit m/s^2. This uses the three-point second-difference stencil , avoiding the extra noise amplification of two successive first derivatives.

Applications

  • Deriving velocity and acceleration from position or displacement sensors in motion control and robotics.
  • Computing rate-of-change alarms in process monitoring (e.g. pressure or temperature slope detection).
  • Edge and slope detection as a preprocessing stage before peak detection or thresholding.
  • Estimating current from measured charge, or EMF from flux, in electromagnetics and instrumentation pipelines.

Neat

The stored `last_value`/`last_ts` state means splitting a stream into arbitrary block sizes gives bit-identical results to processing it as one buffer — the block boundary is invisible.

The `5point` stencil is fourth-order accurate ($O(h^4)$ error) versus second-order for `central`, so on smooth signals it is markedly more accurate at the same sample rate, but it is also more sensitive to noise.

Known issues

Finite differencing amplifies high-frequency noise; broadband sensor noise can dominate the output. Smooth or filter noisy signals before differentiating.

One-sided stencils are used at the very first block start (no prior state) and at signal boundaries, which are lower-order and slightly less accurate than the interior central/5-point estimates.

See also

differentiationfinite-differencerate-of-changestatefulcalculussignal-processing