S9 · Lesson 48 · Digital control lab
Zero-order-hold discretization, the critical gain of a sampled loop with and without a computation delay, Tustin PI coefficients, prewarping and coefficient rounding
Lessons 41 and 42 described what sampling does to a loop: the hold's lag, the computation delay, the Tustin approximation, the trouble with poles near z = 1. In this lab you'll see each effect in numbers by building the pieces of a digital controller: discretize a plant exactly, find by simulation the gain at which a sampled loop goes unstable, write a PI law as a difference equation, design a filter corner that lands where it should after warping, and measure what rounding does to a slow pole.
- The curves are the closed-loop pole magnitudes of a sampled first-order plant (Φ = 0.607, Γ = 0.787) under proportional control, against the gain .
- Without delay the pole is , leaving the unit circle at = 2.04.
- With one sample of computation delay the poles solve ; once complex, their magnitude is , which reaches 1 at = 1.27. One sample of delay costs 38% of the usable gain.
Predict
A PI controller ( = 1, = 10 ms) is discretized by Tustin's method at T = 1 ms. With the error held at 1 from the first sample, what does it output at sample 4 (the fifth sample)?
Tustin integrates with the trapezoid rule, so a constant error from k = 0 gives : at k = 4, . The continuous PI would output 1.4 at t = 4 ms; the half-sample lead is the trapezoid counting the first sample's interval as half-filled.
Name it
What the lab computes
- ZOH discretization of : , .
- Critical gain of (no delay) or (one-sample delay): found by simulating the loop and bisecting on whether the response decays, then compared with and .
- Tustin PI: with and .
- Prewarping: Tustin maps an analog frequency to the digital , so a digital corner needs an analog design at .
- Rounding: a pole stored to B fractional bits becomes round, with effective time constant .
Check
Write critical_gain(Phi, Gamma, delay): the gain at which the sampled loop with plant and proportional control (on , or on when delay is True) becomes unstable, by bisection between 0 and 10 on whether after 2000 steps from y = 1 (zero reference) is below 1.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write tustin_pi(Kp, Ti, T) returning , and run_pi(b0, b1, errors) returning the outputs of from rest.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write prewarp(fc, fs): the analog corner that Tustin's method maps to fc at sample rate fs, and tustin_maps(fa, fs): the digital frequency an analog fa lands on.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write quantized_tau(tau, T, bits): round the pole to the nearest multiple of and return the time constant it really represents.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a single sample of computation delay lower the gain at which a sampled loop goes unstable so much?
Without the delay, the controller reacts to the measurement in the same sample, and the closed loop is first order: the pole moves along the real axis and leaves the unit circle only when the gain pushes it below minus one. A one-sample delay adds a second pole to the loop, and as the gain rises the two poles meet and become a complex pair whose magnitude grows with the square root of the gain, so they reach the unit circle sooner, and the loop rings before it goes unstable. In frequency terms, the extra sample is extra phase lag at every frequency, which eats into the phase margin the loop had.