Discretising a controller: Euler versus Tustin
About this lesson
A controller designed with s has to become a few lines of arithmetic before a computer can run it. Follow one lead controller for a motor through two recipes: forward Euler, s ≈ (z − 1)/T, and Tustin's trapezoid rule, s ≈ (2/T)(z − 1)/(z + 1). Both give three numbers for the same four-line loop. Sampled fast, both work. Sampled slowly, Euler's controller turns unstable and the loop blows up, while Tustin's stays stable.
A controller designed in s
A motor's shaft position is 1/(s(s + 1)). The lead controller C(s) = 50(s + 1)/(s + 10) makes the closed loop 50/(s² + 10s + 50): poles −5 ± 5j and 4.3% overshoot. It is a continuous-time design. A computer must now run it.
plant G(s) = 1 / (s(s + 1)) y'' + y' = u controller C(s) = 50(s + 1) / (s + 10) C·G = 50 / (s(s + 10)) (the zero cancels the pole at -1) closed loop 50 / (s² + 10s + 50) poles -5 ± 5j ζ = 0.707 ωn = 7.07 rad/s step y = 1 - e^(-5t)(cos 5t + sin 5t) peak 1.043 at t = 0.63 s (4.3 % overshoot)
Read the lesson step by step
A controller designed in s
A motor's shaft position is 1/(s(s + 1)). The lead controller C(s) = 50(s + 1)/(s + 10) makes the closed loop 50/(s² + 10s + 50): poles −5 ± 5j and 4.3% overshoot. It is a continuous-time design. A computer must now run it.
plant G(s) = 1 / (s(s + 1)) y'' + y' = u controller C(s) = 50(s + 1) / (s + 10) C·G = 50 / (s(s + 10)) (the zero cancels the pole at -1) closed loop 50 / (s² + 10s + 50) poles -5 ± 5j ζ = 0.707 ωn = 7.07 rad/s step y = 1 - e^(-5t)(cos 5t + sin 5t) peak 1.043 at t = 0.63 s (4.3 % overshoot)A computer only has samples
The computer reads y once every T seconds and holds u between readings, as in "The sampled control loop: ADC, computer, DAC". It cannot integrate or differentiate a signal. It can only do arithmetic on stored numbers, so C(s) must become a difference equation.
C(s) = U/E means u' + 10u = 50(e' + e) derivatives need the signal at every instant; the computer only has e[k] = e(kT), k = 0, 1, 2 ... wanted: a rule of the form u[k] = A·u[k-1] + B0·e[k] + B1·e[k-1] three numbers, four lines of code. z means 'one sample later' (the Z-transform): z·x[k] = x[k+1]Forward Euler: s ≈ (z − 1)/T
Forward Euler estimates a slope from the next sample: dx/dt ≈ (x[k+1] − x[k])/T. Writing z for 'one sample later', that is s ≈ (z − 1)/T. Put it into C(s) and the pole at s = −10 lands at z = 1 − 10T.
forward Euler (forward rectangle) dx/dt ≈ (x[k+1] - x[k]) / T → s ≈ (z - 1)/T C(z) = 50·((z-1)/T + 1) / ((z-1)/T + 10) = 50·(z - (1 - T)) / (z - (1 - 10T)) pole s = -10 → z = 1 - 10T zero s = -1 → z = 1 - T (exact mapping would be z = e^(sT) = e^(-10T))Euler gives three numbers
That becomes u[k] = A·u[k−1] + B0·e[k] + B1·e[k−1], with A = 1 − 10T, B0 = 50, B1 = −50(1 − T). At T = 0.02 s: A = 0.80, B0 = 50, B1 = −49. The code stays fixed; only the numbers change.
import math K, a, p, T = 50, 1, 10, 0.02 A, B0, B1 = 1 - p*T, K, -K*(1 - a*T) # forward Euler y = v = u1 = e1 = 0.0 peak, h, us = 0.0, 0.005, [] for k in range(round(3 / T)): e = 1.0 - y # sample the position u = A*u1 + B0*e + B1*e1 # the difference equation u1, e1 = u, e us.append(u) for _ in range(round(T / h)): # motor y'' + y' = u, u held E = math.exp(-h) y, v = y + v*(1 - E) + u*(h - 1 + E), v*E + u*(1 - E) peak = max(peak, y) print(round(peak, 3)) # 1.043 A = 1 - 10·0.02 = 0.80 B0 = 50 B1 = -49Tustin: the trapezoid rule
Tustin's method adds up area with trapezoids, averaging the old and new samples. That gives s ≈ (2/T)(z − 1)/(z + 1), the bilinear transform from the Signals course. The pole at s = −10 now lands at z = (2 − 10T)/(2 + 10T).
trapezoid rule (Tustin, bilinear) x[k+1] = x[k] + T·(x'[k] + x'[k+1]) / 2 → s ≈ (2/T)·(z - 1)/(z + 1) C(z) = 50·((2+T)z - (2-T)) / ((2+10T)z - (2-10T)) pole s = -10 → z = (2 - 10T)/(2 + 10T) zero s = -1 → z = (2 - T)/(2 + T)Tustin's three numbers
Same code, different numbers: A = (2 − 10T)/(2 + 10T), B0 = 50(2 + T)/(2 + 10T), B1 = −50(2 − T)/(2 + 10T). At T = 0.02 s: A = 0.818, B0 = 45.9, B1 = −45.0. The exact pole e^(−0.2) is 0.819.
import math K, a, p, T = 50, 1, 10, 0.02 A, B0, B1 = (2-p*T)/(2+p*T), K*(2+a*T)/(2+p*T), -K*(2-a*T)/(2+p*T) # Tustin y = v = u1 = e1 = 0.0 peak, h, us = 0.0, 0.005, [] for k in range(round(3 / T)): e = 1.0 - y # sample the position u = A*u1 + B0*e + B1*e1 # the difference equation u1, e1 = u, e us.append(u) for _ in range(round(T / h)): # motor y'' + y' = u, u held E = math.exp(-h) y, v = y + v*(1 - E) + u*(h - 1 + E), v*E + u*(1 - E) peak = max(peak, y) print(round(peak, 3)) # 1.058 A = 1.8/2.2 = 0.818 B0 = 45.9 B1 = -45.0 Euler's A = 0.80; exact e^(-0.2) = 0.819Sample fast: both work
Run both at T = 0.02 s, fifty samples a second. Both stay close to the continuous design: peaks 1.043 (Euler) and 1.058 (Tustin) against 1.043. When T is small next to the system's time scales, any sensible recipe works.
T = 0.02 s (50 Hz) peak controller pole continuous 1.043 s = -10 Euler 1.043 z = 0.80 Tustin 1.058 z = 0.818 exact e^(-pT) z = 0.819 The small extra overshoot comes mostly from the DAC holding u for T: on average half a sample late.Where the pole lands
Now slow the sampling and follow the controller's pole. A difference equation is stable only while its pole stays inside |z| < 1. Euler's 1 − 10T passes −1 at T = 0.2 s. Tustin's (2 − 10T)/(2 + 10T) never reaches −1.
controller pole against sample period T T (s) exact Euler Tustin 0.02 0.819 0.800 0.818 0.10 0.368 0.000 0.333 0.20 0.135 -1.000 0.000 0.25 0.082 -1.500 -0.111 stable while |z| < 1 Euler: |1 - 10T| < 1 ⇔ T < 2/10 = 0.2 s Tustin: |2 - 10T| < 2 + 10T for every T > 0Sample slowly: Euler blows up
At T = 0.25 s Euler sets A = −1.50: every sample the controller multiplies its last output by −1.50. The drive signal u goes 50, −135, 268, −541 and keeps growing, flipping sign each time. The motor leaves ±2 after 0.73 s.
import math K, a, p, T = 50, 1, 10, 0.25 A, B0, B1 = 1 - p*T, K, -K*(1 - a*T) # forward Euler y = v = u1 = e1 = 0.0 peak, h, us = 0.0, 0.005, [] for k in range(round(3 / T)): e = 1.0 - y # sample the position u = A*u1 + B0*e + B1*e1 # the difference equation u1, e1 = u, e us.append(u) for _ in range(round(T / h)): # motor y'' + y' = u, u held E = math.exp(-h) y, v = y + v*(1 - E) + u*(h - 1 + E), v*E + u*(1 - E) peak = max(peak, y) print([round(x) for x in us[:4]]) # [50, -135, 268, -541] A = 1 - 10·0.25 = -1.50 (outside the unit circle) the stable C(s) became an unstable C(z)Tustin bends but holds
At T = 0.25 s Tustin gives A = −0.111, inside the circle: it settles, but overshoots 53%. The hold adds a delay the design never saw. Tustin kept it stable. To keep it accurate, sample faster or design the controller with the hold included.
import math K, a, p, T = 50, 1, 10, 0.25 A, B0, B1 = (2-p*T)/(2+p*T), K*(2+a*T)/(2+p*T), -K*(2-a*T)/(2+p*T) # Tustin y = v = u1 = e1 = 0.0 peak, h, us = 0.0, 0.005, [] for k in range(round(3 / T)): e = 1.0 - y # sample the position u = A*u1 + B0*e + B1*e1 # the difference equation u1, e1 = u, e us.append(u) for _ in range(round(T / h)): # motor y'' + y' = u, u held E = math.exp(-h) y, v = y + v*(1 - E) + u*(h - 1 + E), v*E + u*(1 - E) peak = max(peak, y) print(round(peak, 2)) # 1.53 A = (2 - 2.5)/(2 + 2.5) = -0.111 B0 = 25.0 B1 = -19.44 exact e^(-2.5) = 0.082 peak 1.53 (continuous design 1.043)Why Tustin is the safe choice
Euler maps the stable left half s-plane onto everything left of z = 1, which spills outside the unit circle. Tustin maps it exactly onto the inside of the circle, so a stable C(s) always gives a stable C(z). The price: warped frequencies.
s-plane left half (Re s < 0) maps to Euler z = 1 + sT Re z < 1 (too big) Tustin z = (1 + sT/2)/(1 - sT/2) |z| < 1 (exactly) Tustin's warp: a frequency w in C(s) appears at (2/T)·atan(w·T/2) in C(z); 'prewarping' fixes one w. in practice (python-control): import control as ct C = ct.tf([50, 50], [1, 10]) Cd = ct.sample_system(C, 0.02, method='tustin') # method='euler' gives forward Euler
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01Forward Euler replaces s by which expression?
Forward Euler estimates the slope from the next sample, (x[k+1] − x[k])/T, and z means one sample later, so s ≈ (z − 1)/T. (2/T)(z − 1)/(z + 1) is Tustin and (z − 1)/(zT) is backward Euler.
02C(s) has a pole at s = −10. With forward Euler, for which sample periods T is the controller stable?
Forward Euler puts the pole at z = 1 − 10T. It must stay inside the unit circle, |1 − 10T| < 1, so 0 < T < 2/10 = 0.2 s.
03At T = 0.25 s Tustin gives A = −0.111 and the loop settles, yet it overshoots 53% instead of 4.3%. Why?
Tustin keeps the controller stable, but the sample-and-hold acts roughly like a delay of T/2. At T = 0.25 s that lag erodes the design's damping. Faster sampling, or a redesign that accounts for the hold, restores the response.
04Which statement about Tustin's method (the bilinear transform) is true?
Tustin maps Re s < 0 onto |z| < 1, so stability is always kept. Its cost is frequency warping: a frequency w in C(s) appears at (2/T)·atan(wT/2), which prewarping can correct at one chosen frequency.
05When the recipe or the sample period changes, what must change in the four-line controller loop?
Both recipes give the same first-order difference equation u[k] = A·u[k−1] + B0·e[k] + B1·e[k−1]. Only the coefficients depend on the recipe and on T.
Glossary
- Discretisation
- Turning a continuous-time controller C(s) into a discrete-time one C(z), a difference equation a computer can run once per sample.
- Sample period T
- The time between two readings of the sensor and two updates of the output, in seconds. Its inverse is the sample rate.
- Difference equation
- A rule that computes the next output from stored past values, such as u[k] = A·u[k−1] + B0·e[k] + B1·e[k−1].
- Forward Euler
- Approximates a derivative by the slope to the next sample, so s ≈ (z − 1)/T. Simple, but it can turn a stable controller unstable when T is large.
- Tustin's method (bilinear transform)
- Integrates with trapezoids, so s ≈ (2/T)(z − 1)/(z + 1). It maps every stable s-plane pole inside the unit circle.
- Unit circle
- The circle |z| = 1 in the z-plane. A discrete-time system is stable when all its poles lie strictly inside it.
- Zero-order hold
- The DAC keeps each output value constant until the next sample, which acts roughly like a delay of half a sample.
- Frequency warping
- Tustin's squeezing of the frequency axis: a frequency w in C(s) appears at (2/T)·atan(wT/2) in C(z).
Notes and sources
- The motor, the controller and both sample periods are round illustrative numbers. Every curve is computed from the sampled loop: the controller runs its difference equation every T, the DAC holds u, and the motor follows the exact solution of y'' + y' = u between samples.
- Holding u constant for T acts roughly like a delay of T/2. At T = 0.02 s that delay is 0.01 s and barely shows; at T = 0.25 s it is 0.125 s, which is why even Tustin overshoots 53% there. A common practice is to sample many times faster than the closed-loop bandwidth.
- A third recipe, backward Euler, s ≈ (z − 1)/(zT), is always stable too, but it maps the left half-plane onto only a small disc inside the unit circle, so it distorts the response more than Tustin.
- The Python on each step is plain Python 3 with the math module and prints the same numbers as the figure. python-control's sample_system and TransferFunction.sample accept method='euler' (forward difference) and method='tustin' or 'bilinear'.
- G. F. Franklin, J. D. Powell, A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson (ch. 8 Digital control)
- N. S. Nise, Control Systems Engineering, 8th ed., Wiley
- K. Ogata, Modern Control Engineering, 5th ed., Pearson
- L. Schenato, Control Laboratory lecture 18: forward Euler, backward Euler and Tustin discretisation and stability, University of Padua
- MIT OpenCourseWare 16.06 Principles of Automatic Control (S. Hall)
- MIT OpenCourseWare 6.302 Feedback Systems (Roberge, Dawson, Lundberg)
- python-control documentation: TransferFunction.sample (methods euler, bilinear/tustin, backward_diff, zoh)
- python-control documentation: sample_system
- SciPy documentation: scipy.signal.cont2discrete (gbt, bilinear, euler, backward_diff)
- Bilinear transform (stability mapping and frequency warping)
Quiz Unlocks after the last step.