Discrete d/dt
DiscreteComputes 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 . 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:
In the -domain, the transfer function corresponds to:
At low frequencies (), the frequency response accurately approximates continuous differentiation:
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 at a 1 kHz update rate ( s). Routing the position signal through a DiscreteDerivative block with sampleTime = 0.001 provides real-time angular velocity feedback , 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 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 . 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 . Always pre-filter or post-filter noisy physical signals using a low-pass filter.
- Initial Sample Response: Because no prior sample is available on step , the output initializes safely to zero () to eliminate numerical start-up spikes.
- Sampling Period Consistency: Ensure the configured
sampleTimeaccurately 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 ( and ), 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 ().
- Smooth: First-order exponential moving average filter for noise suppression before differentiation.