Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 37 · Digital Control

Discretization Methods

Convert continuous controllers and plants to discrete time with forward Euler, backward Euler, Tustin (bilinear) and zero-order hold, and compare accuracy and stability.

You have designed a controller in continuous time (a lead compensator, a PID, a state-space design). To run it on a microcontroller you need a difference equation. Discretization is the translation. Several methods exist, they behave differently, and picking the wrong one can ruin a good design. This lesson compares the four you will meet most often.

There are two different jobs:

  • Discretizing a plant (the continuous process behind a zero-order hold): this is exact if you use the ZOH method.
  • Discretizing a controller (a continuous design you want to run digitally): this is always an approximation; Tustin is the usual choice.

The four methods

All except ZOH replace s with a function of z:

Method Substitution Idea Stability
Forward Euler s = (z - 1)/T x' ≈ (x[k+1] - x[k])/T can make stable systems unstable
Backward Euler s = (z - 1)/(T z) x' ≈ (x[k] - x[k-1])/T keeps stability, over-damps
Tustin (bilinear) s = (2/T)(z - 1)/(z + 1) trapezoidal integration maps s-LHP exactly into the unit circle
Zero-order hold exact solution with piecewise-constant input what the DAC really does exact for plants
flowchart TD
    A["Continuous model"] --> B{"What are you discretizing?"}
    B -->|"Plant behind a DAC"| C["ZOH: exact"]
    B -->|"Controller from a continuous design"| D["Tustin (default)"]
    D --> E["Prewarp if a frequency must match"]
    B -->|"Quick and simple, small T"| F["Backward Euler"]

A quick decision guide.

What each method does to a pole

Take a continuous pole s and see where each method puts it for T = 0.1. The exact answer is z = e^(sT).

Python Where do the poles land?

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

  • Forward Euler puts the fast pole at -30 at z = -2: unstable, although the continuous pole was stable. It only works when T is small compared with the fastest time constant.
  • Backward Euler always keeps a stable pole stable and lands at 0.25 for s = -30, but it damps too strongly (the exact value is 0.05).
  • Tustin keeps stability (|z| < 1 for every s in the left half plane) but maps s = -100 to z = -0.667, an oscillating discrete pole that does not exist in the continuous system: fast poles turn into ringing.
  • ZOH/exact simply gives e^(sT); it is the reference.

Discretizing a controller

Here is C(s) = (s + 2)/(s + 8) sampled at T = 0.05 s. SciPy's cont2discrete supports all four methods, and Tustin is simple enough to do by hand: substitute s = (2/T)(z-1)/(z+1) and clear the fraction.

Python cont2discrete for four methods, and Tustin by hand

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The Tustin result (0.875 z - 0.7917)/(z - 0.6667) corresponds to the difference equation

TEXT
u[k] = 0.6667·u[k-1] + 0.875·e[k] - 0.7917·e[k-1]

which is two multiplications and an addition per sample. That is the whole controller.

Frequency-response accuracy

How faithfully does each discretized controller reproduce the original frequency response? Evaluate H(e^{jωT}) and compare it with C(jω).

Python Magnitude and phase versus frequency

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Tustin follows the continuous magnitude closely up to about ω = 10 (where ωT = 0.5), then slowly drifts; phase starts to deviate near ω = 20. Backward Euler is accurate only at low frequency, forward Euler overshoots the gain, and the ZOH version of a controller gains about 15% at high frequency, because it effectively adds a half-sample delay and its gain rises in a way the original filter never did. Moral: use ZOH for plants, Tustin for controllers.

Frequency warping and prewarping

Tustin compresses the entire infinite s-axis into the finite arc of the unit circle, so frequencies are warped: ω_d = (2/T)·tan(ωT/2). Low frequencies are almost unchanged; near fs/2 the warping is severe. If you need one critical frequency to match exactly (a notch filter, a crossover), use prewarping: design the continuous filter at ω' = (2/T)·tan(ωT/2) instead of ω before applying Tustin. SciPy's cont2discrete(..., method="bilinear") does plain Tustin; prewarping is a manual step before it.

Discretizing a state-space plant

For x' = Ax + Bu with a ZOH on u, the exact sampled model is x[k+1] = Ad x[k] + Bd u[k] with Ad = e^(AT) and Bd = ∫0^T e^(Aτ) dτ B, computed from a single expm (shown in State-Space Models). Everything from the state-space chapter carries over: use place_poles(Ad, Bd, z_poles), solve_discrete_are for discrete LQR, and the same controllability rank tests.

Two checks after any discretization: (1) stability of the closed loop, not just of the controller; (2) the phase margin at the digital crossover, because the hold and any computation delay subtract about ωc·T·(0.5 to 1.5) of phase. If the margin vanishes, reduce T before touching gains.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which method is exact for a plant behind a DAC with a zero-order hold?

    ZOH discretization uses the exact solution for a piecewise-constant input, which is what the DAC does.
  2. 2. A stable continuous pole at s = -30 and T = 0.1 under forward Euler maps to:

    z = 1 + sT = 1 - 3 = -2, which is outside the unit circle.
  3. 3. Which method maps the whole left half s-plane into the unit circle?

    The bilinear transform maps the imaginary axis onto the unit circle and the left half plane to its inside.
  4. 4. What is prewarping for?

    Tustin warps frequencies as tan(wT/2); prewarping compensates at one chosen frequency.

Summary

  • Discretize plants with ZOH (exact) and controllers with Tustin (stable, accurate at low ωT).
  • Forward Euler can destabilize a stable system; backward Euler is stable but over-damps.
  • Tustin warps frequency (tan(ωT/2)); prewarp when one frequency must match.
  • The state-space tools (expm, place_poles, discrete LQR) work unchanged on (Ad, Bd).
  • Always re-check closed-loop stability and margins after discretizing.

Next: Digital PID Implementation