The two crossover frequencies and the two margins
The gain crossover frequency
The phase crossover frequency
Phase margin:
Gain margin:
A pressure loop runs well for a year. Then someone adds a filter to the noisy transmitter signal, or the signal is routed through a slower network, and the pump begins to hunt up and down without stopping. Nothing was broken and no tuning setting was touched. The loop was stable, but it was close to its stability limit, and nobody had measured how close. Frequency response gives that measurement: this lesson shows how to compute the gain margin, the phase margin and the delay margin of a loop, and what each number allows the plant to do. #FrequencyResponse #BodePlot #StabilityMargins
By the end of this lesson, you will be able to:
A booster pump with a variable speed drive holds the pressure in a water line. A pressure transmitter on the discharge sends its signal to a PI controller, and the controller sets the drive speed. The loop has been tuned and it settles well after a tap opens.
The maintenance team wants to make three changes. They want a filter on the pressure signal, they want to read the transmitter through a gateway that updates once per second, and they want to raise the controller gain for a faster response. Each change is small. The question is whether the loop will still be stable after each one, and after all three together.
A step test shows only that the loop is stable today. Frequency response shows the distance to instability as numbers: how many times the gain can rise, and how many seconds of delay can be added, before the loop oscillates.
Put a sine wave into a linear process and wait for the start-up effects to pass. The output is a sine wave of the same frequency, changed only in size and timing.
The gain is the ratio of output amplitude to input amplitude. The phase is the shift in time, written as an angle: a full cycle is 360°, so an output that is one quarter of a cycle late has a phase of
To find them from a transfer function
A Bode plot is two graphs against frequency on a logarithmic axis: the gain and the phase. The gain is often given in decibels:
A gain of 1 is 0 dB, a gain of 2 is 6 dB, a gain of 10 is 20 dB and a gain of 0.1 is
For the first-order process
The frequency
| Frequency | Gain | Phase |
|---|---|---|
A first-order lag can never shift the phase by more than
For
For a dead time
This is the dangerous element. Its phase lag grows in proportion to frequency and has no limit, while its gain stays at 1. A lag reduces the signal as it delays it. A dead time delays the signal at full strength.
| 0.1 | 0.5 | 1.0 | 1.57 | 3.14 | |
|---|---|---|---|---|---|
| Phase of the dead time |
The loop transfer function is the controller times the process,
For a PI controller in ISA form,
At low frequency the PI controller acts as an integrator (large gain, phase
Think of a small sine wave that travels once round the loop. The negative feedback at the comparison point reverses it, a shift of
So the dangerous condition is a loop gain of 1 or more at the frequency where the loop phase is
The two crossover frequencies and the two margins
The gain crossover frequency
The phase crossover frequency
Phase margin:
Gain margin:
Read the plot in two moves. Find where the gain curve crosses 1, go down to the phase curve, and measure how far the phase is above
Common targets for a process loop are a gain margin of at least 2 (6 dB) and a phase margin of 45° to 60°. A gain margin of 2 means the process gain can double, for example when a pump moves to a steeper part of its curve. Both margins are needed. A loop can have a large gain margin and a small phase margin, or the reverse.
Extra dead time changes only the phase. An extra delay of
The delay margin is in seconds, which makes it the easiest margin to explain on site. Signal filters, slow sample times, network links and a sensor moved further along a pipe all use part of it.
A faster loop has a higher crossover frequency. The phase lag of the dead time at crossover is
No setting of a PID controller removes this limit. A loop with a dead time of 0.5 s cannot have a crossover much above 1 rad/s and keep a good margin. The only ways to a faster loop are a shorter dead time (a sensor closer to the pump, a faster transmitter, a shorter sample time) or a different control structure.
For a second-order loop with no dead time, the damping ratio of the closed loop is roughly
for phase margins below about 60°. A phase margin of 45° suggests
Margins come from a linear model at one operating point. They do not see a drive at its speed limit, a valve that sticks, or a pump curve whose slope changes with flow. A loop with good margins at 60 percent speed can have poor margins at 90 percent if the process gain is higher there. Compute the margins at the operating point with the highest process gain and the longest dead time.
Closed-loop time constant.
Controller gain.
✅
Integral time.
Loop transfer function. Write the PI controller as
✅
Simplify. Because
The loop is an integrator with a gain of 0.5 and a dead time of 0.5 s. The number 2 is
Loop gain. The dead time has a gain of 1, so
Gain crossover. Set the loop gain to 1:
✅
Loop phase. The integrator gives
✅
Phase at crossover.
Phase margin.
Phase crossover. Set the loop phase to
✅
Loop gain there.
Gain margin.
Meaning for the settings. With all else fixed, the controller gain could rise from 15 to
The table gives points of the Bode plot of this loop, from the script in the Python section.
| Loop gain | Loop gain (dB) | Loop phase | |
|---|---|---|---|
| 0.1 | 5.000 | 14.0 | |
| 0.2 | 2.500 | 8.0 | |
| 0.5 | 1.000 | 0.0 | |
| 1.0 | 0.500 | ||
| 2.0 | 0.250 | ||
| 3.142 | 0.159 | ||
| 5.0 | 0.100 |
Find the gain crossover. The gain column passes through 1.000 (0 dB) at
Read the phase there. The phase at that row is
Find the phase crossover. The phase column passes through
Read the gain there. The gain at that row is 0.159, or
Check the slope. The gain falls from 5.000 to 0.500 between 0.1 and 1.0 rad/s, a factor of 10 for one decade. That is the
Why. Step 1 cancelled the controller zero against the process lag. Check the crossover with each block computed separately, as the script does. ✅
Controller at 0.5 rad/s.
Process at 0.5 rad/s.
Loop. Gain:
Root finding. The script solves
Phase margin in radians.
Delay margin.
✅
Total dead time at the limit.
Period at the limit. Extra dead time does not change the gain, so the crossover stays at 0.5 rad/s and the loop oscillates at that frequency:
Method. The loop is simulated with a time step of 0.001 s and a dead-time buffer of
Extra 2.0 s. The swing falls from 0.2261 bar to 0.0050 bar. The loop is stable, but it rings for a long time. ✅
Extra 2.642 s. The swing is 1.0787 bar and then 1.0836 bar. The oscillation neither grows nor decays: the loop is at its limit, as computed. ✅
Extra 3.2 s. The swing grows from 5.835 bar to 34.97 bar. The loop is unstable. In a real plant the drive would reach its speed limits and the pressure would swing between them. ✅
| Extra dead time | Swing, 20 to 60 s | Swing, 80 to 120 s | Result |
|---|---|---|---|
| 0 s | 0.0000 bar | 0.0000 bar | settled |
| 2.0 s | 0.2261 bar | 0.0050 bar | decays |
| 2.642 s | 1.0787 bar | 1.0836 bar | sustained |
| 3.2 s | 5.835 bar | 34.97 bar | grows |
Added delay. Gateway 1.0 s plus filter 0.2 s gives about 1.2 s. (A first-order filter is a lag and not a pure delay, but at frequencies well below its corner it acts like a delay equal to its time constant.) ✅
Compare with the delay margin. 1.2 s is less than 2.64 s, so the loop stays stable. The delay margin that remains is
New phase margin. The added lag at crossover is
Judgement. The loop would work, with more overshoot and less margin than a commissioning engineer should accept. The team must not also raise the gain. A better design keeps the fast signal path direct to the controller and sends a copy through the gateway for records. ✅
The script computes the margins by root finding on the full loop formulas, prints the table used in Application 1, simulates the loop with extra dead time and saves the Bode plot.
import numpy as npfrom scipy.optimize import brentqimport matplotlib.pyplot as plt
# Plant B (booster pump) and the lambda = 3*theta PI settings, ISA formK, tau, theta = 0.10, 3.0, 0.5 # bar/percent, s, slam = 3 * thetaKc, Ti = tau / (K * (lam + theta)), tau # percent/bar, sprint(f"Kc = {Kc:.2f} percent/bar, Ti = {Ti:.2f} s")
def gain(w): """|L(jw)|: PI controller times FOPDT. Dead time has gain 1.""" return Kc * K * np.sqrt(1 + 1 / (w * Ti) ** 2) / np.sqrt(1 + (w * tau) ** 2)
def phase(w): """arg L(jw) in radians, not wrapped. Dead time adds exactly -w*th.""" return np.arctan(w * Ti) - np.pi / 2 - np.arctan(w * tau) - w * theta
w_c = brentq(lambda w: gain(w) - 1.0, 1e-3, 1e2) # gain crossoverw_180 = brentq(lambda w: phase(w) + np.pi, 1e-3, 1e2) # phase crossoverpm = np.pi + phase(w_c) # radiansgm = 1.0 / gain(w_180)dm = pm / w_c # delay margin, sprint(f"gain crossover w_c = {w_c:.4f} rad/s")print(f"phase crossover w_180 = {w_180:.4f} rad/s")print(f"phase margin PM = {np.degrees(pm):.2f} deg")print(f"gain margin GM = {gm:.3f} ({20 * np.log10(gm):.1f} dB)")print(f"delay margin DM = {dm:.3f} s (total dead time {theta + dm:.3f} s)")print(f"period at the limit = {2 * np.pi / w_c:.2f} s")
print("\n w (rad/s) |L| |L| dB phase (deg)")for w in (0.1, 0.2, 0.5, 1.0, 2.0, np.pi, 5.0): print(f" {w:8.3f} {gain(w):7.3f} {20 * np.log10(gain(w)):7.1f} " f"{np.degrees(phase(w)):10.1f}")
def closed_loop(extra, t_end=120.0, dt=0.001, dr=0.5): """Setpoint step of dr bar with dead time theta + extra. No limits.""" n, nd = int(round(t_end / dt)), int(round((theta + extra) / dt)) buf, pos, a = np.zeros(nd), 0, np.exp(-dt / tau) y, integ, out = 0.0, 0.0, np.zeros(n) for k in range(n): e = dr - y integ += e * dt u = Kc * (e + integ / Ti) out[k] = y delayed, buf[pos] = buf[pos], u pos = (pos + 1) % nd y = a * y + (1 - a) * K * delayed return np.arange(n) * dt, out
print("\n extra dead time swing 20-60 s swing 80-120 s result")for extra in (0.0, 2.0, round(dm, 3), 3.2): t, y = closed_loop(extra) s1 = np.ptp(y[(t >= 20) & (t < 60)]) s2 = np.ptp(y[t >= 80]) verdict = "decays" if s2 < 0.8 * s1 else ("grows" if s2 > 1.25 * s1 else "sustained") print(f" {extra:6.3f} s {s1:8.4f} bar {s2:8.4f} bar {verdict}") if extra == 0.0: overshoot = max(0.0, (y.max() - 0.5) / 0.5 * 100)print(f"overshoot with no extra dead time = {overshoot:.1f} percent")
w = np.logspace(-2, 1.2, 600)fig, ax = plt.subplots(2, 1, figsize=(8, 7), sharex=True)ax[0].semilogx(w, 20 * np.log10(gain(w))); ax[0].axhline(0, color="k", lw=0.5)ax[0].axvline(w_c, ls=":"); ax[0].set_ylabel("|L| (dB)")ax[0].set_title(f"Loop gain, pump with PI: PM {np.degrees(pm):.1f} deg, GM {gm:.2f}")ax[1].semilogx(w, np.degrees(phase(w))); ax[1].axhline(-180, color="k", lw=0.5)ax[1].axvline(w_c, ls=":"); ax[1].axvline(w_180, ls="--")ax[1].set_ylim(-360, 0); ax[1].set_ylabel("phase (deg)")ax[1].set_xlabel("frequency (rad/s)")fig.tight_layout(); fig.savefig("loop_margins_bode.png", dpi=120)Expected output
Kc = 15.00 percent/bar, Ti = 3.00 sgain crossover w_c = 0.5000 rad/sphase crossover w_180 = 3.1416 rad/sphase margin PM = 75.68 deggain margin GM = 6.283 (16.0 dB)delay margin DM = 2.642 s (total dead time 3.142 s)period at the limit = 12.57 s
w (rad/s) |L| |L| dB phase (deg) 0.100 5.000 14.0 -92.9 0.200 2.500 8.0 -95.7 0.500 1.000 0.0 -104.3 1.000 0.500 -6.0 -118.6 2.000 0.250 -12.0 -147.3 3.142 0.159 -16.0 -180.0 5.000 0.100 -20.0 -233.2
extra dead time swing 20-60 s swing 80-120 s result 0.000 s 0.0000 bar 0.0000 bar decays 2.000 s 0.2261 bar 0.0050 bar decays 2.642 s 1.0787 bar 1.0836 bar sustained 3.200 s 5.8350 bar 34.9682 bar growsovershoot with no extra dead time = 0.0 percentThe phase function in the script is written without wrapping. A phase computed with np.angle jumps by 360° when it passes
1. The pump process without its dead time is
Corner:
2. A dead time of 0.5 s is in a loop. Find its gain and phase at
Gain is 1 at every frequency. Phase at 2 rad/s:
3. The hot water tank has
4. For the pump loop with
5. The Ziegler-Nichols open-loop PI settings for the pump are
Root finding gives
6. A first-order filter with a time constant of 0.2 s is added to the pressure signal of the pump loop of Application 1. Its transfer function
Multiply the gain by
A pressure loop is stable and settles well. A pure delay is added to the measurement signal: every value arrives later, but its size is not changed at all. No tuning setting is touched. Can the delay alone make the loop oscillate without end?
The loop is the booster pump (K = 0.10 bar per percent, τ = 3 s) with a PI controller. Read the plot in two moves. First find where the gain curve crosses 0 dB, go down to the phase curve, and measure how far the phase is above −180°: that gap is the phase margin. Then find where the phase curve crosses −180°, go up to the gain curve, and measure how far the gain is below 0 dB: that gap is the gain margin. Raising Kc lifts the whole gain curve and does not move the phase curve. More dead time bends the phase curve down and does not move the gain curve. The delay margin is the phase margin in radians divided by ωc.
Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.
1. A loop is an integrator with a dead time of 0.5 s. Its gain crossover is at 0.5 rad/s. The integrator gives −90° of phase. What is the phase margin?
2. A report gives the gain margin of a loop as 6 dB. By what factor can the loop gain rise before the loop is at its limit?
3. The pump loop has Kc = 15, Ti = 3 s and a dead time of 0.5 s. Its gain margin is 6.28 and its phase margin is 75.7°. The controller gain is doubled to 30. What are the margins now?
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.