Gain and Phase Margins, Delay and the Nichols Chart
The heater block of the intro reads its temperature through a thermistor glued to the far side of the block: the sensor sees a change about late. A PI controller that was comfortable without the delay now rings, and with a little more gain it oscillates. How close to the edge is a loop, and how much delay, gain error or model error can it take before it fails? Stability margins answer that with two or three numbers that every control datasheet and tuning report quotes.
The definitions
For a stable open loop (see Nyquist for why the margins measure distance to the point ):
| Margin | Where it is read | Definition | Typical target |
|---|---|---|---|
| gain margin | phase crossover , where | , or in dB | () |
| phase margin | gain crossover , where | to | |
| delay margin | gain crossover | : the extra delay that destroys the phase margin | larger than any delay you cannot rule out |
| peak sensitivity | frequency of the peak | , the inverse of the shortest distance to | 1.3 to 2 |
The gain margin says how much the loop gain may grow (a hotter heater, a stronger motor, a wrong sensor scale) before instability. The phase margin is linked to damping: for a loop that behaves like a second-order system, for margins up to about , so gives roughly 20–25 % overshoot and about 10 %. guards against both at once and against nearby "almost crossings" that the two classic margins miss.
Delay: phase lag without gain
A pure delay has unit magnitude and phase (radians). It leaves unchanged and subtracts from the phase margin. Sources of delay in real loops: transport (a fluid in a pipe), sensor placement (the thermistor above), sampling and computation (about sample periods for a sampled controller, see Sampled-Data Loops), and communication over fieldbuses. Rational methods such as Routh cannot handle ; frequency-response margins can, exactly. python-control needs a rational approximation for time responses: ct.pade(theta, n) returns the numerator and denominator of an -th order Padé approximant.
Worked example: PI on the heater with a sensor delay
Given: (K/W), PI controller with (zero on the plant pole) and .
Find: , the phase margin, the gain margin, the delay margin.
Solve: with the zero on the pole, .
- Gain crossover: gives .
- Phase there: ; .
- Phase crossover: needs ; , so ().
- Delay margin: . The loop tolerates the sensor being up to about late in total.
Check: the figure marks both margins; the program computes them on a dense frequency grid with the exact delay and compares with python-control on a Padé model.
import numpy as np
import control as ct
Kp, Ti, theta = 3.0, 300.0, 10.0
w = np.logspace(-4, 0, 200001)
L = Kp * (1 + 1 / (1j * w * Ti)) * 4 * np.exp(-1j * w * theta) / (300j * w + 1)
ic = np.argmin(abs(abs(L) - 1))
ph = np.unwrap(np.angle(L))
ip = np.argmin(abs(ph + np.pi))
pm = 180 + np.degrees(ph[ic])
print(f"exact delay : w_c = {w[ic]:.4f} rad/s, PM = {pm:.1f} deg, "
f"w_pc = {w[ip]:.4f} rad/s, GM = {1 / abs(L[ip]):.3f} ({-20 * np.log10(abs(L[ip])):.1f} dB)")
print(f" delay margin {np.radians(pm) / w[ic]:.1f} s, Ms = {max(abs(1 / (1 + L))):.2f}")
num, den = ct.pade(theta, 6)
Lp = ct.tf([Kp * Ti, Kp], [Ti, 0]) * ct.tf([4], [300, 1]) * ct.tf(num, den)
gm, pmp, wpc, wgc = ct.margin(Lp)
print(f"Pade(6) : w_c = {wgc:.4f} rad/s, PM = {pmp:.1f} deg, w_pc = {wpc:.4f} rad/s, GM = {gm:.3f}")
info = ct.step_info(ct.feedback(Lp, 1), T=np.linspace(0, 400, 8001))
print(f"closed-loop step: overshoot {info['Overshoot']:.1f} %, settling {info['SettlingTime']:.0f} s")exact delay : w_c = 0.0400 rad/s, PM = 67.1 deg, w_pc = 0.1571 rad/s, GM = 3.927 (11.9 dB)
delay margin 29.3 s, Ms = 1.44
Pade(6) : w_c = 0.0400 rad/s, PM = 67.1 deg, w_pc = 0.1571 rad/s, GM = 3.927
closed-loop step: overshoot 0.1 %, settling 55 s
The closed-loop step settles in with practically no overshoot (, of which part is the Padé model's ripple); a phase margin of is on the safe side. Raising to would triple to , leave only , and make the loop ring badly.
Intuition with the Bode lab
The Bode lab reads both margins directly. At its defaults (three poles at , , , ): phase margin at , gain margin at . Add of gain and the loop would sit exactly on the edge. Move the third pole down from (a slower sensor) and watch the phase margin shrink while the gain crossover barely moves: extra lag near crossover costs margin, just like a delay.
The Nichols chart: an overview
The Nichols chart plots the open-loop response as in dB (vertical) against in degrees (horizontal), with frequency as a parameter along the curve. The critical point becomes . Its advantages: a gain change shifts the whole curve vertically without changing its shape, and a background grid of contours of constant closed-loop magnitude (M-contours, the Nichols-chart images of the Nyquist-plane M-circles) and phase lets you read the closed-loop resonance peak directly. Gain margin is the vertical distance below the critical point where the curve crosses ; phase margin the horizontal distance where it crosses . It was the tool of choice for hand design with graph paper; today it survives in loop-shaping tools and some drive tuning software. python-control draws it with ct.nichols_plot(L) and the grid with ct.nichols_grid().
Guided lab: measure the delay margin of the heater loop
Hand calculation. For your block, identify , and the sensor delay from an open-loop step (see Model-Based Tuning). With , choose for : .
Simulation. Put your numbers into the program; check and .
What you would measure. The heater on a current-limited supply through a logic-level MOSFET with PWM, the thermistor or a digital sensor read by a microcontroller. Add a software delay buffer to the measurement (e.g. 0, 10, 20, 30 s) and log a setpoint step of for each. Expect the overshoot to grow with the added delay and sustained oscillation near the predicted delay margin, typically within 20 % (the thermal model is only first order plus delay). The oscillation period at the limit is about .
Hazards and safe setup. The resistor and block get hot (keep the setpoint at or below , mount on a heat-resistant base, add a thermal fuse or a software cut-off at ), current limit about , never unattended.
Pitfalls
- Quoting a gain margin for an unstable open loop: margins assume ; use Nyquist instead.
- Looking only at and : a loop can have both large and still pass close to between them; check .
- Forgetting delays that do not appear in the model: sampling, filtering, PWM, communication.
- Reading python-control's
marginoutput in the wrong order:(gm, pm, w_pc, w_gc).
Practice
- . Find , and the delay margin.
- A loop has and . A digital controller adds of delay. What is the new phase margin?
- On a Nichols chart, how does doubling the controller gain move the curve?
Answer
- ; ; delay margin (on top of the ).
- : .
- Up by , shape unchanged.
Test yourself
The phase margin is measured at
- the frequency where
- the frequency where
- zero frequency
- the closed-loop bandwidth
A loop with and tolerates how much extra delay?
- about 1.7 s
- about 29 s
- about 67 s
- unlimited
Why can't Routh–Hurwitz analyse a loop with a pure delay exactly?
- delays are unstable
- is not a rational function, so there is no finite characteristic polynomial
- delays have no frequency response
- Routh only works for first-order systems
On the Nichols chart the critical point is
- the origin of the complex plane