Δ

Discrete d/dt

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

Computes the discrete-time numerical derivative of an incoming signal using the backward difference (Backward Euler) approximation. Evaluates the rate of change by dividing the difference between the current sample and previous sample by the sampling period TsT_s. Essential for calculating velocities and accelerations from position sensors, constructing derivative channels in digital PID controllers, and estimating discrete state trajectories in embedded control systems.

Mathematical Model

In the discrete-time domain, the backward difference equation is expressed as:

y[n]={0,if n=0u[n]−u[n−1]Ts,if n≥1y[n] = \begin{cases} 0, & \text{if } n = 0 \\ \frac{u[n] - u[n-1]}{T_s}, & \text{if } n \ge 1 \end{cases}

In the Z\mathcal{Z}-domain, the transfer function corresponds to:

H(z)=Y(z)U(z)=1−z−1Ts=z−1Ts⋅zH(z) = \frac{Y(z)}{U(z)} = \frac{1 - z^{-1}}{T_s} = \frac{z - 1}{T_s \cdot z}

At low frequencies (ωTs≪1\omega T_s \ll 1), the frequency response accurately approximates continuous differentiation:

∣H(ejωTs)∣=2Tssin⁡(ωTs2)≈ω|H(e^{j\omega T_s})| = \frac{2}{T_s} \sin\left(\frac{\omega T_s}{2}\right) \approx \omega

Inputs & Outputs

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

Parameters

Parameters Label Type Default Description
sampleTime Sample Time number 0.01

Usage Examples

Example 1: Velocity Estimation from Incremental Position Sensors

In servomotor motion control, an optical encoder measures cumulative shaft angle θ[n]\theta[n] at a 1 kHz update rate (Ts=0.001T_s = 0.001 s). Routing the position signal through a DiscreteDerivative block with sampleTime = 0.001 provides real-time angular velocity feedback ω[n]≈dθ/dt\omega[n] \approx d\theta/dt, closing the inner velocity damping loop without requiring an analog tachometer.

Example 2: Discrete Derivative Action in Digital PID Controllers

In discrete PID regulation loops, computing the derivative of the tracking error e[n]=r[n]−y[n]e[n] = r[n] - y[n] provides predictive phase lead to prevent overshoot. Feeding the error through a DiscreteDerivative block produces the rate of change, which is then multiplied by derivative gain KdK_d. Cascading a discrete first-order filter (Smooth block) immediately after the derivative attenuates high-frequency sensor noise.

Remarks & Best Practices

  • Noise Amplification: Pure numerical differentiation behaves as an ideal high-pass filter whose gain scales with frequency, magnifying high-frequency quantization noise by 1/Ts1 / T_s. Always pre-filter or post-filter noisy physical signals using a low-pass filter.
  • Initial Sample Response: Because no prior sample u[−1]u[-1] is available on step n=0n = 0, the output initializes safely to zero (y[0]=0y[0] = 0) to eliminate numerical start-up spikes.
  • Sampling Period Consistency: Ensure the configured sampleTime accurately corresponds to the execution timestep of your discrete subsystem or target microcontroller clock.
  • Strict Causality: The backward difference formulation depends strictly on present and past data (u[n]u[n] and u[n−1]u[n-1]), making it fully causal and directly synthesizable into embedded C/Rust firmware.

Related Components

  • Derivative: Continuous-time differentiator featuring an internal high-frequency filtering pole.
  • DiscreteIntegrator: Discrete accumulator implementing Forward Euler, Backward Euler, or Tustin integration.
  • UnitDelay: Delays a discrete signal by exactly one sample period (z−1z^{-1}).
  • Smooth: First-order exponential moving average filter for noise suppression before differentiation.