---
title: Gain and phase margin
heading: Judging a loop's stability from the Bode plot of its loop gain, the crossover where the gain falls to one, the phase there and the phase margin, the gain margin at the frequency where the phase reaches −180°, the delay a loop can tolerate, and the link between phase margin and damping
eyebrow: D3 · Lesson 7 · Gain and phase margin
xp: 40
---

::: hook
A loop goes unstable when a signal travels around it and comes back the same size and exactly inverted, because the subtraction at the input then turns into an addition and the signal sustains itself. Engineers rarely solve for poles to check this. They measure or plot the loop gain's Bode plot and ask two questions: how far is the gain below one where the phase reaches −180°, and how far is the phase from −180° where the gain is one? Those two numbers, the **gain margin** and the **phase margin**, say how robust a loop is, and they can be measured on real hardware.
:::

::: play
- The loop gain of a plant with three equal lags, $L(s) = K/(s + 1)^3$, like a heater feeding three thermal masses in a row.
- The phase reaches −180° at $\omega = \sqrt{3}$ rad/s, where the gain is K/8: the gain margin is 8/K.
- The gain crosses one at $\omega_c = \sqrt{K^{2/3} - 1}$, and the phase margin is how far the phase there sits above −180°. Raising K shrinks both margins; at K = 8 the loop oscillates.
:::

```sim plot
view: bode
x: w = 0.05..20 rad/s log
slider: K = 1.2..10 step 0.1 = 2
H: K/(1 + j*w)^3
marker: x = sqrt(3) | label: phase −180°
marker: x = sqrt(K^(2/3) - 1) | label: crossover
readout: gain margin, dB = 20*log(8/K) | digits: 3
readout: phase margin, ° = 180 - 3*atan(sqrt(K^(2/3) - 1))*180/pi | digits: 3
```

::: predict
## With K = 2, the loop $K/(s + 1)^3$ crosses unity gain at 0.766 rad/s with 67.6° of phase margin. How much pure time delay could be added before it goes unstable?

- [ ] 0.67 s
- [x] About 1.5 s
- [ ] About 88 s
- [ ] Any amount: delay doesn't change the gain

::: reveal
A delay T doesn't change the gain but subtracts $\omega T$ radians of phase. The loop goes unstable when that eats the whole margin at the crossover: T = (67.6° × π/180)/0.766 = 1.18/0.766 = 1.54 s. Delay is the classic way a well-behaved loop is pushed into oscillation, which is why fast loops need fast sensors.
:::
:::

::: nameit
## Crossovers and margins

On the Bode plot of the loop gain $L(j\omega)$:

- the **gain crossover** $\omega_c$ is where $|L| = 1$ (0 dB). The **phase margin** is $PM = 180° + \angle L(j\omega_c)$;
- the **phase crossover** $\omega_{180}$ is where $\angle L = -180°$. The **gain margin** is $GM = 1/|L(j\omega_{180})|$, or $-20\log_{10}|L(j\omega_{180})|$ dB.

For a typical loop whose gain falls steadily, the closed loop is stable when both margins are positive. Common targets are a phase margin of 45° to 60° and a gain margin of at least 6 dB.

## Margins and the response

For a loop that behaves like a second-order system, the closed-loop damping ratio is roughly $\zeta \approx PM/100°$ for margins up to about 70°: 60° of margin gives about 10% overshoot, 30° gives a ringing response with about 37%.

## Delay margin

A time delay T multiplies L by $e^{-j\omega T}$, which costs phase $\omega T$ (in radians) at every frequency without changing the gain. The largest tolerable delay is

$$T_\text{max} = \frac{PM\,(\text{rad})}{\omega_c}$$
:::

::: example
## Find the margins of $K/(s + 1)^3$ at K = 4.

::: solution
1. **Gain margin.**
   $$8/4 = 2$$
   or 6.0 dB.
2. **Crossover.**
   $$\begin{aligned} \omega_c &= \sqrt{4^{2/3} - 1} \\ &= 1.233\ \text{rad/s} \end{aligned}$$
3. **Phase margin.** The phase at crossover is
   $$\begin{aligned} \phi &= -3\arctan 1.233 \\ &= -152.9° \end{aligned}$$
   so PM = 27.1°.
4. **Delay margin.**
   $$\begin{aligned} T_d &= \frac{27.1 \times \pi/180}{1.233} \\ &= 0.38\ \text{s} \end{aligned}$$
5. **How it behaves.** This loop rings badly: ζ is roughly 0.27.

**Answer:** a gain margin of 2 (6.0 dB), a phase margin of 27.1° and a delay margin of 0.38 s.
:::
:::

::: example
## A loop's gain is 0.25 where its phase reaches −180°, and its phase is −130° where its gain is 1. What are its margins, and roughly what overshoot should you expect?

::: solution
1. **Gain margin.**
   $$1/0.25 = 4$$
   or 12 dB.
2. **Phase margin.**
   $$180 - 130 = 50°$$
   so ζ ≈ 0.5.
3. **Overshoot.**
   $$e^{-\pi \times 0.5/0.866} = 16\%$$

**Answer:** a gain margin of 4 (12 dB) and a phase margin of 50°, so expect about 16% overshoot.
:::
:::

::: example
## A loop crosses over at 10 rad/s with 45° of phase margin. How much pure delay can it tolerate?

::: solution
1. **What delay costs.** A delay $T_d$ subtracts $\omega T_d$ radians at the crossover.
2. **Delay that uses up the margin.**
   $$\begin{aligned} T_d &= \frac{45 \times \pi/180}{10} \\ &= 78.5\ \text{ms} \end{aligned}$$
3. **Where delay comes from.** Networked or sampled controllers add delay, and this is the budget it comes out of.

**Answer:** it can tolerate 78.5 ms of delay.
:::
:::

::: check
given: g = 0.1 | 0.3 | 0.5 | 0.8
answer: -20*log(g)
unit: dB
tolerance: 0.5%

## A loop's gain is {g} at the frequency where its phase reaches −180°. What's its gain margin?

::: right
Right. $-20\log_{10}|L|$ = {answer} dB.
:::

::: misses
- [20*log(g)] The margin is positive for a stable loop.
- [any] Not yet. How many dB of extra gain until |L| = 1.
:::
:::

::: check
given: p = 115 | 135 | 150 | 165
answer: 180 - p
unit: °
tolerance: 0.5%

## A loop's phase is −{p}° at the frequency where its gain is 1. What's its phase margin?

::: right
Right. 180° − {p}° = {answer}°.
:::

::: misses
- [any] Not yet. Distance from −180°.
:::
:::

::: check
given: m = 30 | 45 | 60; w = 0.5 | 10 | 200
answer: m*pi/180/w*1000
unit: ms
tolerance: 0.5%

## A loop has {m}° of phase margin at a crossover of {w} rad/s. How much time delay can it tolerate before going unstable?

::: right
Right. $PM/\omega_c$ with PM in radians: {answer} ms.
:::

::: misses
- [m/w*1000] Convert the margin to radians first.
- [any] Not yet. Delay costs $\omega T$ of phase.
:::
:::

::: check
given: K = 1.5 | 3 | 5
answer: 20*log(8/K)
unit: dB
tolerance: 0.5%

## What's the gain margin of $L(s) = \given{K}/(s + 1)^3$?

::: right
Right. At $\omega = \sqrt{3}$ the gain is K/8, so GM = 8/K, or {answer} dB.
:::

::: misses
- [8/K] Express it in decibels.
- [any] Not yet. Find where three equal lags reach −180°.
:::
:::

::: check
kind: parts
given: w = 2 | 10 | 50; P = 30 | 45 | 60

## A loop crosses over at {w} rad/s with {P}° of phase margin.

::: part
answer: P*pi/180/w*1000
unit: ms
tolerance: 0.5%

### What delay margin does it have?

::: misses
- [any] $\text{PM (rad)}/\omega_c$.
:::
:::

::: part
answer: P/100
tolerance: 0.5%

### Roughly what damping ratio does the rule of thumb ζ ≈ PM/100 give?

::: misses
- [any] PM in degrees ÷ 100.
:::
:::
:::

::: check
kind: parts
given: K = 2 | 4 | 6

## The loop $K/(s + 1)^3$ has gain {K}.

::: part
answer: 8/K
tolerance: 0.5%

### What is its gain margin, as a ratio?

::: misses
- [any] The gain reaches 8 where the phase is −180°.
:::
:::

::: part
answer: 180 - 3*asin(sqrt(K^(2/3) - 1)/sqrt(1 + K^(2/3) - 1))*180/pi
unit: °
tolerance: 0.5%

### What is its phase margin?

::: misses
- [any] At $\omega_c = \sqrt{K^{2/3} - 1}$, PM = 180° − 3 arctan $\omega_c$.
:::
:::
:::

::: explain
## Why does a time delay in a feedback loop push it toward instability?

::: model
A delay passes every frequency at the same size but shifts it later in time, which is a phase lag that grows in proportion to frequency. Around the gain crossover, where the loop's gain is one, the phase margin measures how far the loop is from turning its negative feedback into positive feedback. The delay's extra lag eats into that margin, and once the lag at the crossover equals the margin, a signal at that frequency returns around the loop the same size and inverted, so it sustains itself as an oscillation. Fast loops have high crossover frequencies, so even a short delay costs them a lot of phase.
:::
:::

::: practice

::: check
given: g = 0.01 | 0.1 | 0.25 | 0.5 | 0.8 | 0.95
answer: -20*log(g)
unit: dB
tolerance: 0.5%

## GM from |L| = {g} at −180°?

::: misses
- [any] $-20\log|L|$.
:::
:::

::: check
given: m = 10 | 80; w = 0.1 | 5000
answer: m*pi/180/w*1000
unit: ms
tolerance: 0.5%

## Delay margin: {m}° at {w} rad/s?

::: misses
- [any] PM in radians over $\omega_c$.
:::
:::

::: check
given: K = 1.1 | 1.5 | 2 | 3 | 4 | 5 | 7.5
answer: 180 - 3*atan(sqrt(K^(2/3) - 1))*180/pi
unit: °
tolerance: 0.5%

## Phase margin of $\given{K}/(s + 1)^3$?

::: misses
- [any] Find $\omega_c = \sqrt{K^{2/3} - 1}$, then 180° − 3 arctan $\omega_c$.
:::
:::
:::
