Skip to main content

Differentiation and Integration

Calculus

Differentiation "derive"1

The function derive() differentiates the input signal x(t)x(t) with respect to time.

y=ddtx(t),[y]=[x]sy = \frac{d}{dt}x(t), \quad [y] = \frac{[x]}{\mathrm{s}}

Without a JSON configuration, derive() computes the instantaneous quotient Δx/Δt\Delta x / \Delta t between two consecutive evaluation timestamps. This simple mode is only meaningful when the input signal is genuinely linearly interpolable, for example equidistantly sampled values with #interpolateLin.

For equidistant signals the grid mode is recommended: fOut resamples the input onto a uniform time grid and differentiates it with a sliding FIR differentiator of order nFilt. The FIR filter forms a weighted difference quotient over the last 2nFilt2 \cdot \texttt{nFilt} grid points, enabling a trade-off between noise suppression and phase delay.

For signals with a cyclic value range (e.g. angle counters 0°..360° or incremental encoders with overflow) the modulo parameter enables an overflow correction. The function detects overflows using the overflow zone ovflz and corrects the gradient so that no sign jump occurs in the derivative result.

y1 = derive(x);
y2 = derive(x, { fOut: <dbl>|'def'
, nFilt: <uint>
, reduction: <uint>
, modulo: <dbl>
, ovflz: <dbl>
});
PropertyValueDescription
fOutdef/<dbl>Output sampling frequency for grid mode in Hz. 'def' uses the global sampling time (discreteSampleTimeMs). Minimum value: 0.1 Hz.
nFilt<uint>Filter order of the sliding FIR differentiator. Higher values reduce noise at the cost of phase delay. Only effective in grid mode.
Default: 2, range: [210][2 \ldots 10]
reduction<uint>Outputs only every n-th computed grid point. Enables an output rate below fOut. Values ≤ 1 are ignored.
modulo<dbl>Enables overflow correction for cyclic signals. Specifies the full value range (e.g. 360.0 for angles in degrees, 6.2832 for angles in radians).
Range: >0.0> 0.0
ovflz<dbl>Overflow zone as a fraction of modulo. An overflow is detected when the new value occupies the zone [0, ovflzmodulo[[0,\ \mathtt{ovflz} \cdot \mathtt{modulo}[ and the previous one the zone ](1ovflz)modulo, modulo]](1-\mathtt{ovflz}) \cdot \mathtt{modulo},\ \mathtt{modulo}] (or vice versa).
Default: 0.333, range: ]0.0;0.5[]0.0; 0.5[
note

Since the smartCORE typically writes non-equidistant signal values to a single channel only when the value has changed, the value between two explicit support points must always be assumed to be constant, and the information for the last, actual sampling interval is missing. Between the sampling points, the signal value on the left side always applies (zero-order hold). This results in a staircase-shaped signal waveform.

Applying differentiation to non-equidistant signals with a staircase-like profile is meaningless. The result would be either 00 or ±\pm \infty

Integration "integrate"

The function integrate() returns the time integral of the input function x

y=0tx(τ)dτy = \int_0^tx(\tau)d\tau

Since x(τ)x(\tau) always provides individual support points at non-equidistant time points t0,t1,t2,...tnt_0, t_1, t_2, ... t_n, between which the left-hand side function value is assumed to be constant, the integral can also be written as a sum:

y=n=0N1x(tn)(tn+1tn)y = \sum_{n=0}^{N-1}x(t_n)(t_{n+1}-t_n)

The physical unit of the result is extended by a time dimension: [y]=[x]s[y] = [x] \cdot \rm{s}.

note

For equidistant signals, trapezoidal integration is planned for the future.

I1 = integrate(y);
I2 = integrate(y, reset);
I3 = integrate(y, reset, preset);
// Optional configuration for all variants
Ix = integrate(..., { start: <dbl>
, preset: <dbl>
, lower: off|<dbl>
, upper: off|<dbl>
, storage: <str>
});

If true is supplied via the optional parameter reset, the integral is reset to the value specified by preset (as a parameter or property, default 0.0) and held. Immediately before the reset, an additional sample is inserted, which outputs the last integral value accumulated up to that point ("true peak").

PropertyValueDescription
start<dbl>Initial value for the integral when the Math module starts
preset<dbl>Fixed value for resetting the integral via the reset parameter
loweroff/<dbl>Limits the integral value downward, if enabled. This is required, for example, for the implementation of control structures or models where the integration process is limited by a physical boundary.
upperoff/<dbl>Limits the integral value from above, if enabled. This is required, for example, for the implementation of control structures or models in which the integration process is limited by a physical boundary.
storage<str>Name of a persistent storage for the internal integral value. This ensures that integration continues from the last saved value after a system restart.
The contents of this storage cannot be used anywhere else in smartCORE.

Example:

In Example 1a, the integrate() function is used to calculate electrical energy from current and voltage waveforms.

In Example 10, the integrate() function is used to measure times.

Summation "sumup"

The function sumup() returns the sum of individual values of the input signal x at the times of a positive edge on the trigger parameter

y=n=0N1x(tn)wheretn=time(posedge(trigger))y = \sum_{n=0}^{N-1}x(t_n)\quad\rm{where}\quad t_n=time(posedge(trigger))
S1 = sumup(x, trigger);
S2 = sumup(x, trigger, reset);
// Optional configuration for all variants
Sx = sumup(... , { storage: <str>
});

If true is supplied via the optional parameter reset, the sum is reset to 0.0 and held.

PropertyValueDescription
storage<str>Name of a persistent storage location for the internal sum value. This ensures that after a system restart, the sum continues from the last saved value.
The contents of this storage cannot be used anywhere else in smartCORE.

Footnotes

  1. Available from Catalog Version 13.