Derivative kick and filtering: choose what D responds to

Explain derivative kick and filtering with a target step and measured noise. Compare derivative on error with derivative on measurement, calculate filtered command peaks, and weigh noise gain against lag.

By 11 min read

What you will learn

  • Explain why an ideal derivative produces an impulse at a reference step.
  • Distinguish derivative on error from derivative on measurement.
  • Calculate the peak and decay of a filtered derivative kick.
  • Calculate sinusoidal noise gain and lag relative to an ideal derivative.
  • Derive a sampled filter update and state what its approximation leaves out.

Before you start

A target can jump before a robot moves. Derivative action on error reacts to that target jump. Derivative action on measurement reacts to measured motion, including sensor noise.

You will calculate both effects and see how a first-order filter changes them. The parallel PID form documented by MathWorks includes a separate derivative-filter time constant for this purpose.

Define derivative kick and filtering

Let r be the reference, y the true output, and yₘ = y + n the measurement. The sensor contribution n can contain noise. Define the measured tracking error as e = r − yₘ.

This lesson isolates the derivative contribution D to a PID command. All signals use normalized units, and time uses seconds. Kd has units of seconds, so multiplying a signal rate by Kd produces a command in normalized units.

We use two prescribed signal tests. Neither test closes a feedback loop or predicts robot motion:

  • A reference steps at t = 0.5 s while yₘ stays zero. This filter starts at rest.
  • A measurement follows n(t) = A sin(2πft) while y stays zero. This filter starts in its steady periodic state.

The second test represents one frequency component of noise. It does not describe every sensor's noise spectrum.

Differentiate a reference step

An ideal derivative on error gives:

Dₑ = Kd ė = Kd(ṙ − ẏₘ)

Let the reference jump by Δr while the measurement remains unchanged. A mathematical step has no finite slope at the jump. Its derivative is a Dirac impulse, so the ideal derivative command has impulse area Kd Δr.

The area has units of command times seconds. It is not a finite peak that a plot can represent with a tall line. A sampled implementation produces a finite value that depends on its sample time and derivative rule.

This target-driven contribution is derivative kick. It can request a large command before the plant has moved.

Put derivative action on measurement

Derivative on measurement uses the same opposing sign:

Dₘ = −Kd ẏₘ
Dₑ − Dₘ = Kd ṙ

When the reference stays constant, the two ideal expressions agree. At a reference step, Dₘ has no direct target-driven impulse. For a moving plant, the derivative contribution still changes as the measured output changes.

This choice does not remove the proportional command's response to a target step. It also does not remove measurement noise from the derivative branch. A jump in the measured signal can still create a derivative pulse.

MathWorks calls a controller with proportional and integral action on error, plus derivative action on output, a PI-D controller. Its target response differs from a controller that differentiates the full error.

Add a first-order derivative filter

Replace the ideal derivative Kd s with:

Hᴅ(s) = Kd s / (1 + Tf s), with Tf > 0

For derivative on error, feed e into Hᴅ. For derivative on measurement, feed −yₘ into Hᴅ. Tf is the filter time constant in seconds; the filter adds a pole at −1/Tf.

One realization uses a low-pass state x for the chosen input v:

Tf ẋ = v − x
D = (Kd/Tf)(v − x)

The state x remains continuous through an input step, while D can jump. This filtered derivative has a finite high-frequency gain Kd/Tf. Its high-frequency gain stays nonzero when Kd is positive, so filtering does not erase all high-frequency content.

Calculate a filtered kick

For a reference step Δr at t₀, a filter initially at rest gives:

Dₑ(t) = 0, for t < t₀
Dₑ(t) = (Kd Δr/Tf) exp(−(t − t₀)/Tf), for t ≥ t₀

Use Kd = 0.5 s, Tf = 0.1 s, and Δr = 1. The right-hand value at the jump is 0.5 × 1 / 0.1 = 5. One time constant later, it falls to 5/e = 1.839397.

The full pulse area is Kd Δr = 0.5 s, independent of Tf. Increasing Tf lowers the peak and spreads the pulse over more time. The ideal derivative on error and the filtered derivative share this area; their peak behavior differs.

If the measurement remains zero, derivative on measurement remains zero. The target-step plot compares these two inputs to the same filter.

Follow measured noise through the derivative

Hold true output at zero and let measurement noise be n(t) = A sin(ωt), where ω = 2πf. The ideal derivative on measurement is:

Dₘ,ideal(t) = −Kd A ω cos(ωt)

Its amplitude is Kd A ω. Doubling frequency doubles this ideal command amplitude when A and Kd stay fixed.

Write a = ωTf. In steady periodic operation, the filtered derivative is:

Dₘ,filtered(t) = −Kd A ω [cos(ωt) + a sin(ωt)] / (1 + a²)
Amplitude = Kd A ω / √(1 + a²)

With A = 0.02, f = 5 Hz, and the previous Kd and Tf, the ideal amplitude is 0.314159. The filtered amplitude is 0.095289. Its RMS over a full period is 0.095289/√2 ≈ 0.067380.

The formula includes no startup transient. In the low-pass realization, the periodic initial state for v = n is x(0) = −A a/(1 + a²); the measurement derivative uses the negative of that branch output. Starting x at zero would add a decaying transient to the same eventual periodic response.

Weigh noise gain against lag

The low-pass factor multiplying the ideal derivative has magnitude and phase:

Relative magnitude = 1 / √(1 + (ωTf)²)
Additional lag = atan(ωTf)
Filter corner f꜀ = 1 / (2πTf)

The lag is relative to the ideal derivative of the same input. With Tf = 0.1 s at 5 Hz, it is 72.343213°. The filter corner is 1.591549 Hz, where the low-pass factor has magnitude 1/√2 and adds 45° of lag.

Increasing Tf to 0.4 s lowers the filtered noise amplitude to 0.024921, while increasing the additional lag to 85.450135°. That lag also affects useful measured motion entering the derivative branch.

At high frequency, command amplitude approaches A Kd/Tf. For A = 0.02, Kd = 0.5 s, and Tf = 0.1 s, the limit is 0.1. The derivative filter limits amplification; it does not guarantee small noise, actuator feasibility, or closed-loop stability.

Implement a sampled derivative filter

A digital controller needs a discrete rule. For the continuous relation Tf Ḋ + D = Kd v̇, backward Euler gives this update with sample period h:

D[k] = Tf/(Tf + h) D[k−1] + Kd/(Tf + h) (v[k] − v[k−1])

For a step arriving at sample k = 0, with zero previous state and input, the first value is Kd Δr/(Tf + h). With the worked gains and h = 0.01 s, that value is 4.545455. It differs from the continuous filter's right-hand peak of 5.

After the step, successive values decay by Tf/(Tf + h). This factor lies between zero and one for positive Tf and h, so the filter's free state decays. That fact alone says nothing about the stability of a feedback loop that contains the filter.

The MathWorks discrete PID documentation distinguishes backward Euler from other discretizations. Different rules have different frequency responses. Sampling can alias sensor content above half the sample rate, and a digital filter cannot recover which original frequency produced an aliased sample sequence.

Choose a sample period and an analog sensor or anti-alias filter using the bandwidth of the real signals. The interactive plots below stay in continuous time and do not simulate sampling.

Controller discretization follows a complete loop from a sampled measurement to a held command. It shows how the update period and an extra sample of delay change the closed-loop poles.

Compare the two signal experiments

Start with the default reference step. The blue response jumps to 5 at 0.5 s; the green measurement-derivative response stays zero. Move the replay cursor to 0.6 s and check the value 1.839397.

Select the longer filter time and compare the kick peak with the noise amplitude. Then select the higher noise frequency: the ideal noise amplitude rises to 1.256637, while the filtered amplitude reaches 0.099685, close to its limit of 0.1.

Separate the target step from measured noise

What enters the derivative branch?

Compare a target step with a sinusoidal measurement. Each experiment has an exact formula; neither includes a moving plant or a closed feedback loop.

0.50
0.10
1.00
0.02
5.00

D(s) = Kd s/(1 + Tf s). Reference, measurement, and derivative command use normalized units; Kd and Tf use seconds. A longer Tf reduces the derivative branch’s noise gain and adds lag relative to the ideal derivative.

0.50
Filtered derivative kick from a 1.000000 reference stepMeasurement stays zero. At 0.5 seconds, derivative on error jumps to 5.000000 and decays exponentially. Derivative on measurement stays zero. Separate blue segments preserve the jump. At replay time 0.500000 seconds, derivative on error is 5.000000. The ideal impulse has no finite peak and is not drawn.036012Time (s)Derivative D
Zero initial state: the target steps at 0.5 s while measurement stays zero. Blue: derivative on error. Green dashes: derivative on measurement. The blue curve jumps at the guide and then decays; its dot marks replay time. With Kd or step size zero, both responses stay zero.
Derivative response to 5.000000 hertz measured noiseTwo periods of a prescribed sinusoidal measurement, with true output fixed at zero. Both curves show steady-periodic behavior, with no startup transient. The ideal derivative amplitude is 0.314159. The filtered derivative amplitude is 0.095289. These analytic amplitudes can exceed the sampled curve's extrema slightly.-0.400.40.0000.2000.400Time (s)Derivative D
Steady periodic state: true output stays zero and measurement is A sin(2πft). Orange dashes: ideal derivative on measurement. Blue: filtered derivative on measurement. This independent plot always shows two periods; it does not use the step replay cursor. With A or Kd zero, both curves stay zero.
Derivative on error
5.000000
Derivative on measurement
0.000000
Filtered kick peak
5.000000
Ideal kick impulse area (s)
0.500000
Ideal noise amplitude
0.314159
Filtered noise amplitude
0.095289
Filtered noise RMS
0.067380
Noise gain |D/n|
4.764453
High-frequency gain limit
5.000000
Filter corner (Hz)
1.591549
Lag versus ideal (deg)
72.343213

The filtered noise amplitude remains positive. Filtering limits high-frequency gain; it does not eliminate noise. The corner frequency describes the low-pass factor multiplying the ideal derivative.

Readouts use analytic amplitudes and RMS over a full period. Curves use finite samples. The ideal step derivative is an impulse with area Kd × step size, so it has no finite peak to draw. The filtered step retains that area over infinite time.

These are continuous-time branch tests. They include no actuator limits, delays, sampling, quantization, or feedback stability calculation. Noise starts in its periodic state; the step filter starts at rest.

The noise plot always shows two periods, so its time span changes with frequency. Its amplitudes and RMS come from the formulas, while the visible curves use finite samples. Turning Kd off makes every derivative command zero and leaves phase undefined.

The replay affects only the target-step experiment. The noise response starts in a periodic state that existed before its displayed time origin.

Reproduce the calculations in Python

This standard-library example evaluates the analytic step and sinusoidal formulas. It also takes two backward-Euler updates to expose the digital approximation. It does not simulate a plant.

import math

kd, tf, step = 0.5, 0.1, 1.0
amplitude, frequency = 0.02, 5.0
omega = 2 * math.pi * frequency
a = omega * tf
peak = kd * step / tf
ideal = kd * amplitude * omega
filtered = ideal / math.hypot(1, a)
print(f"Step peak: {peak:.6f}")
print(f"After one Tf: {peak * math.exp(-1):.6f}")
print(f"Noise amplitudes: ideal={ideal:.6f}, filtered={filtered:.6f}")
print(f"Filtered RMS: {filtered / math.sqrt(2):.6f}")
print(f"Added lag: {math.degrees(math.atan(a)):.6f} deg")

h = 0.01
previous_d, previous_input = 0.0, 0.0
updates = []
for value in [step, step]:
    d = (tf * previous_d + kd * (value - previous_input)) / (tf + h)
    updates.append(d)
    previous_d, previous_input = d, value
print(f"Backward Euler: first={updates[0]:.6f}, second={updates[1]:.6f}")

Expected output:

Step peak: 5.000000
After one Tf: 1.839397
Noise amplitudes: ideal=0.314159, filtered=0.095289
Filtered RMS: 0.067380
Added lag: 72.343213 deg
Backward Euler: first=4.545455, second=4.132231

Try it yourself

Exercise 1. Use Kd = 0.4 s, Tf = 0.2 s, and a reference step Δr = 1.5. Measurement stays zero. Find the filtered derivative-on-error peak, its value after one Tf, and the pulse area. What does derivative on measurement produce?

Check the step peak and area

The peak is 0.4 × 1.5 / 0.2 = 3. After 0.2 s it is 3/e = 1.103638. The pulse area is 0.4 × 1.5 = 0.6 s.

Derivative on measurement stays zero because the measurement never changes. The proportional term of a full PID controller can still jump when the reference changes.

Exercise 2. Use Kd = 0.5 s, Tf = 0.1 s, and sinusoidal measurement noise with A = 0.02 at the filter corner frequency. Calculate that frequency, the ideal and filtered derivative amplitudes, and the extra phase lag.

Check the corner-frequency tradeoff

The corner frequency is 1/(2π × 0.1) = 1.591549 Hz. Here ωTf = 1, so the ideal amplitude is Kd A/Tf = 0.1.

The filtered amplitude is 0.1/√2 = 0.070711, with 45° of extra lag relative to the ideal derivative. That amplitude is finite and nonzero. These branch calculations do not establish feedback stability.

Sources and further study

Return to PID tuning with the chosen filter dynamics included. Recheck response and command demands before deciding whether the gains still meet your requirements.