∫

Discrete ∫

Discrete
Run the live example Free · no sign-up · runs in your browser

Computes discrete-time numerical integration (accumulation) of a sampled input signal. Supports three classical discretization algorithms: Forward Euler (explicit with zero direct feedthrough), Backward Euler (implicit, highly stable for stiff dynamics), and Trapezoidal / Tustin (bilinear transform, providing optimal frequency fidelity). Essential for digital PID controllers, discrete state-space compensators, numerical dead-reckoning odometry from velocity sensors, and discrete accumulator registers in embedded DSP systems.

Mathematical Model

The discrete difference equation and corresponding Z\mathcal{Z}-domain transfer function depend on the selected method:

  • Forward Euler (method = "forward"):
y[n]=y[n−1]+Ts⋅u[n−1]  ⟹  H(z)=Tsz−1=Ts⋅z−11−z−1y[n] = y[n-1] + T_s \cdot u[n-1] \implies H(z) = \frac{T_s}{z - 1} = \frac{T_s \cdot z^{-1}}{1 - z^{-1}}
  • Backward Euler (method = "backward"):
y[n]=y[n−1]+Ts⋅u[n]  ⟹  H(z)=Ts⋅zz−1=Ts1−z−1y[n] = y[n-1] + T_s \cdot u[n] \implies H(z) = \frac{T_s \cdot z}{z - 1} = \frac{T_s}{1 - z^{-1}}
  • Trapezoidal / Tustin (method = "trapezoidal"):
y[n]=y[n−1]+Ts2(u[n]+u[n−1])  ⟹  H(z)=Ts2z+1z−1y[n] = y[n-1] + \frac{T_s}{2} \left( u[n] + u[n-1] \right) \implies H(z) = \frac{T_s}{2} \frac{z + 1}{z - 1}

where TsT_s denotes sampleTime and y[0]=y0y[0] = y_0 denotes initialCondition.

When the bottom reset terminal is driven (r[n]>0r[n] > 0), the internal register resets synchronously to the initial condition:

y[n]=y0,if r[n]>0y[n] = y_0, \quad \text{if } r[n] > 0

Inputs & Outputs

Direction ID Label Type Status
→ In in In number Required
→ In reset Reset number Optional
← Out out Out number Output

Parameters

Parameters Label Type Default Description
method Integration Method select forward
initialCondition Initial Condition number 0
sampleTime Sample Time number 0.01

Usage Examples

Example 1: Embedded Digital PID Integral Channel (Tustin Form)

In industrial microcontroller motion control, the integral error term must eliminate steady-state position offset without phase distortion. Wiring the tracking error e[n]e[n] into a DiscreteIntegrator configured with method = "trapezoidal" and sampleTime = 0.002 s (500 Hz500\text{ Hz} loop rate) synthesizes the exact Tustin bilinear transform (KiTs2z+1z−1K_i \frac{T_s}{2} \frac{z+1}{z-1}), reproducing textbook digital integrator behavior with zero algebraic drift.

Example 2: Dead-Reckoning Distance Odometry from Velocity Telemetry

In autonomous mobile robotics (AGVs), wheel tachometers provide linear vehicle velocity v[n]v[n] every 10 ms10\text{ ms} (Ts=0.01T_s = 0.01 s). Routing the velocity signal through a DiscreteIntegrator block with method = "forward" evaluates cumulative position x[n]=x[n−1]+Ts⋅v[n−1]x[n] = x[n-1] + T_s \cdot v[n-1], providing dead-reckoning displacement feedback without creating algebraic loop dependencies in the motion controller.

Remarks & Best Practices

  • Algebraic Loop Mechanics: Because Backward Euler and Trapezoidal methods depend on the current input sample u[n]u[n] (D≠0D \ne 0), placing them in algebraic feedback loops creates an instantaneous dependency that solvers must iterate to resolve. Forward Euler reads strictly from u[n−1]u[n-1] (D=0D = 0), inherently breaking algebraic circular loops.
  • Bilinear Tustin Mapping: The trapezoidal method maps the continuous imaginary frequency axis s=jωs = j\omega uniquely onto the discrete unit circle ∣z∣=1|z| = 1, preserving continuous system stability margins without aliasing.
  • Embedded C Code Generation Parity: The difference equations implemented by this block map directly to scalar accumulator loops in C/Rust, facilitating rapid prototyping for embedded firmware targets.
  • Synchronous Reset Functionality: Driving the optional bottom reset terminal with a positive value (r>0r > 0) immediately reloads initialCondition into the state register.

Frequently Asked Questions (FAQ)

Q: What are the numerical stability and accuracy differences between Forward Euler, Backward Euler, and Trapezoidal (Tustin) integration?

Forward Euler (z−1=sTsz - 1 = s T_s) maps the stable continuous left-half ss-plane into a circle shifted by 1 in the zz-plane; it can easily destabilize stable continuous poles if step size Ts>2/∣λ∣T_s > 2/|\lambda|. Backward Euler (1−z−1=sTs1 - z^{-1} = s T_s) maps the left-half plane strictly inside a circle within the unit disk, providing artificial numerical damping (A-stable, unconditionally stable for linear systems). Trapezoidal / Tustin integration (s=2Tsz−1z+1s = \frac{2}{T_s} \frac{z-1}{z+1}) provides a conformal bilinear mapping preserving exact frequency stability boundaries without artificial energy dissipation, offering second-order accuracy (O(Ts2)O(T_s^2)).

Related Components

  • Integrator: Continuous-time ODE integrator solved by variable-step continuous solvers.
  • DiscreteDerivative: Evaluates backward difference derivatives ((u[n]−u[n−1])/Ts(u[n] - u[n-1]) / T_s).
  • UnitDelay: Fundamental single-sample delay operator (z−1z^{-1}).
  • PIDController: Full three-term controller supporting configurable discretization methods.