---
title: Loop shaping with lead and lag compensators
heading: Designing in the frequency domain by choosing a crossover and the phase there, the lead compensator's maximum phase and where it occurs, the lag compensator's low-frequency gain and its small phase cost, and the type II compensator used in switching power supplies
eyebrow: S9 · Lesson 26 · Loop shaping with lead and lag compensators
xp: 50
---

::: hook
In the frequency domain a design becomes a drawing exercise: decide where the loop gain should cross 0 dB (that sets the speed), make sure the phase there leaves enough margin (that sets the damping), and keep the gain high at low frequencies (that sets the accuracy). A lead compensator adds phase near crossover, a lag compensator adds gain far below it. This is how most analog loops are compensated, from servo amplifiers to the error amplifier inside every switching regulator.
:::

::: play
- The motor position loop $G = 10/(s(0.1s + 1))$ with a lead compensator $K_c\frac{1 + s/\omega_z}{1 + s/(\alpha\omega_z)}$.
- With the defaults ($K_c$ = 2.94, $\omega_z$ = 13.1, α = 2.32) the loop crosses at 20 rad/s, 2.5 times faster than the plain loop's 7.9, with the same 50° phase margin.
- The lead's phase bump peaks at $\sqrt{\alpha}\,\omega_z$. Centering it on the crossover gets the most phase for the least gain.
:::

```sim plot
view: bode
x: w = 0.5..500 rad/s log
slider: K = 0.3..10 = 2.94 log
slider: z = 2..60 = 13.1 rad/s log
slider: a = 1..20 = 2.32 log
H: K*(1 + j*w/z)/(1 + j*w/(a*z))*10/((j*w)*(1 + 0.1*j*w))
marker: x = sqrt(a)*z | label: lead's peak
readout: lead's maximum phase, ° = asin((a - 1)/(a + 1))*180/pi | digits: 3
readout: velocity constant Kv = 10*K | digits: 3
```

::: predict
## A lead compensator with $\omega_p/\omega_z$ = α = 10 adds the most phase at one frequency. How much?

- [ ] 90°
- [x] About 55°
- [ ] About 35°
- [ ] About 39°, its phase at the zero's frequency

::: reveal
At $\omega_m = \sqrt{\omega_z\omega_p}$ the lead adds $\sin^{-1}\frac{\alpha - 1}{\alpha + 1} = \sin^{-1}(9/11)$ = 54.9°, while raising the gain by $\sqrt{\alpha}$ = 3.16 (10 dB). More than about 60° from one lead stage costs too much high-frequency gain, so designs needing more use two.
:::
:::

::: nameit
## Specifications in the frequency domain

- **Crossover $\omega_c$** sets speed: rise time is roughly $1.5/\omega_c$ to $2/\omega_c$.
- **Phase margin** sets damping (lesson 25): 45 to 60° is typical.
- **Low-frequency gain** sets accuracy: $K_v$ or $K_p$ (lesson 10), and disturbance rejection.
- **High-frequency roll-off** keeps noise and unmodeled dynamics out.

## Lead

$$C_\text{lead} = K_c\frac{1 + s/\omega_z}{1 + s/\omega_p}, \qquad \alpha = \frac{\omega_p}{\omega_z} > 1$$

adds up to $\phi_\text{max} = \sin^{-1}\frac{\alpha - 1}{\alpha + 1}$ at $\omega_m = \sqrt{\omega_z\omega_p}$, where its gain is $K_c\sqrt{\alpha}$ (10 log α dB above $K_c$). For a needed phase φ, $\alpha = \frac{1 + \sin\phi}{1 - \sin\phi}$.

**Design:** pick $\omega_c$; find the plant's phase there and the lead φ needed for the margin (plus about 5° if a lag will be added); compute α; set $\omega_z = \omega_c/\sqrt{\alpha}$, $\omega_p = \omega_c\sqrt{\alpha}$; choose $K_c$ so that $K_c\sqrt{\alpha}|G(j\omega_c)| = 1$.

## Lag

$$C_\text{lag} = \frac{s + \omega_z}{s + \omega_p}, \qquad \omega_p < \omega_z$$

has gain $\omega_z/\omega_p$ at DC and 1 at high frequency. With $\omega_z$ about a decade below crossover, it costs only a few degrees there.

## The type II compensator

A switching regulator's error amplifier is usually an integrator with one zero and one pole, $C = \frac{\omega_I(1 + s/\omega_z)}{s(1 + s/\omega_p)}$: the integrator gives zero steady error, and the zero–pole pair is a lead centered on the crossover. A type III compensator adds a second zero–pole pair for plants, like a voltage-mode buck converter's LC filter, that lose 180° of phase.
:::

::: example
## Design a lead so that $G = 10/(s(0.1s + 1))$ crosses at 20 rad/s with a 50° phase margin.

::: solution
1. **Plant at 20 rad/s.**
   $$\begin{aligned} |G| &= \frac{10}{20\sqrt5} \\ &= 0.224 \end{aligned}$$
   (−13.0 dB), and the phase is −153.4°.
2. **Phase the lead must add.** A 50° margin needs −130°, so
   $$\begin{aligned} \phi &= 153.4° - 130° \\ &= 23.4° \end{aligned}$$
3. **Lead ratio.**
   $$\begin{aligned} \alpha &= \frac{1 + \sin 23.4°}{1 - \sin 23.4°} \\ &= 2.32 \end{aligned}$$
4. **Zero, pole and gain.** Centered on 20 rad/s, with $\sqrt\alpha = 1.523$:
   $$\begin{aligned} \omega_z &= 20/1.523 \\ &= 13.1\ \text{rad/s} \\ \omega_p &= 30.5\ \text{rad/s} \\ K_c &= \frac{1}{\sqrt\alpha\,|G|} \\ &= 2.94 \end{aligned}$$
5. **Check.** The loop crosses at 20 rad/s with PM = 50.0°.
6. **Step response.** It overshoots 19% and settles in 0.32 s, against 0.81 s before, and $K_v$ rises from 10 to 29.4.

**Answer:** a lead with α = 2.32, its zero at 13.1 rad/s, its pole at 30.5 rad/s and $K_c$ = 2.94, which crosses at 20 rad/s with a 50.0° phase margin.
:::
:::

::: example
## Add a lag to that design for five times more $K_v$.

::: solution
1. **Place the lag.** Put its zero a decade below crossover, at 2 rad/s, and its pole at 0.4.
2. **Its cost at crossover.** At 20 rad/s it adds
   $$\tan^{-1}10 - \tan^{-1}50 = -4.6°$$
   and changes the gain by only 0.5%.
3. **New margin.**
   $$\begin{aligned} \text{PM} &= 50.0° - 4.6° \\ &= 45.4° \end{aligned}$$
4. **New velocity constant.**
   $$\begin{aligned} K_v &= 29.4 \times 5 \\ &= 147 \end{aligned}$$
5. **Step response.** It now overshoots 27% and settles in 0.53 s, slower because of the lag's slow tail.
6. **A better plan.** Designing the lead for 55° in the first place would have absorbed the lag's cost.

**Answer:** a lag with its zero at 2 rad/s and pole at 0.4 rad/s raises $K_v$ to 147, and the phase margin falls to 45.4°.
:::
:::

::: example
## A loop crosses over at 50 rad/s with a 55° phase margin. Integral action is added by a PI whose zero sits a decade lower, at 5 rad/s. What does it cost?

::: solution
1. **Phase cost.** At crossover the PI factor $1 + \omega_z/(j\omega)$ has phase
   $$-\tan^{-1}(5/50) = -5.7°$$
   leaving a 49.3° margin.
2. **Gain change.** Its magnitude is $\sqrt{1 + 0.01}$, a 0.04 dB rise that barely moves the crossover.
3. **What it buys.** The loop becomes type 1 and rejects constant disturbances completely.
4. **Where to put the zero.** A decade below crossover is the usual compromise; at a factor of 3 the cost would be 18°.

**Answer:** it costs 5.7° of phase margin (leaving 49.3°) and raises the gain at crossover by only 0.04 dB.
:::
:::

::: check
given: a = 2 | 5 | 10 | 20
answer: asin((a - 1)/(a + 1))*180/pi
unit: °
tolerance: 0.5%

## A lead compensator has $\omega_p/\omega_z$ = {a}. What's the most phase it adds?

::: right
Right. $\sin^{-1}\frac{\alpha - 1}{\alpha + 1}$ = {answer}°.
:::

::: misses
- [atan(a)*180/pi - 45] That's the phase at the zero's frequency; the maximum is at $\sqrt{\omega_z\omega_p}$.
- [any] Not yet. $\phi_\text{max} = \sin^{-1}\frac{\alpha - 1}{\alpha + 1}$.
:::
:::

::: check
given: f = 20 | 35 | 50
answer: (1 + sin(f*pi/180))/(1 - sin(f*pi/180))
tolerance: 0.5%

## A lead must add {f}° at its peak. What ratio $\alpha = \omega_p/\omega_z$ does it need?

::: right
Right. $\alpha = \frac{1 + \sin\phi}{1 - \sin\phi}$ = {answer}.
:::

::: misses
- [any] Not yet. Invert $\sin\phi = \frac{\alpha - 1}{\alpha + 1}$.
:::
:::

::: check
given: z = 2 | 10 | 300; a = 3 | 8
answer: sqrt(a)*z
unit: rad/s
tolerance: 0.5%

## A lead has its zero at {z} rad/s and its pole {a} times higher. Where does it add the most phase?

::: right
Right. $\sqrt{\omega_z\omega_p} = \sqrt{\alpha}\,\omega_z$ = {answer} rad/s.
:::

::: misses
- [(1 + a)/2*z] Use the geometric mean, which is the midpoint on a log axis.
- [any] Not yet. $\omega_m = \sqrt{\omega_z\omega_p}$.
:::
:::

::: check
given: K = 5 | 20; t = 0.05 | 0.2; w = 10 | 40; a = 2 | 6
answer: w*sqrt(1 + w^2*t^2)/(K*sqrt(a))
tolerance: 0.5%

## A lead with α = {a} is centered on {w} rad/s to make $G = \given{K}/(s(\given{t}s + 1))$ cross there. What $K_c$ does that take?

::: right
Right. $K_c\sqrt{\alpha}|G(j\omega_c)| = 1$ gives {answer}.
:::

::: misses
- [w*sqrt(1 + w^2*t^2)/K] The lead's own gain at its center is $\sqrt{\alpha}$ times $K_c$.
- [any] Not yet. Make the loop gain 1 at $\omega_c$.
:::
:::

::: check
given: w = 10 | 50; z = 1 | 4; p = 0.1 | 0.5
answer: (atan(w/z) - atan(w/p))*180/pi
unit: °
tolerance: 0.5%

## A lag with its zero at {z} rad/s and pole at {p} rad/s: how much phase does it cost at a {w} rad/s crossover?

::: right
Right. $\tan^{-1}(\omega/\omega_z) - \tan^{-1}(\omega/\omega_p)$ = {answer}°.
:::

::: misses
- [(atan(w/p) - atan(w/z))*180/pi] The pole's lag is larger, so the result is negative.
- [any] Not yet. Zero's phase minus pole's phase.
:::
:::

::: check
given: a = 3 | 10; z = 5 | 20
answer: 10*log(a)
unit: dB
tolerance: 0.05

## How much gain does a lead with α = {a} add at its center frequency, relative to its DC gain?

::: right
Right. $\sqrt{\alpha}$, or 10 log α = {answer} dB.
:::

::: misses
- [20*log(a)] That's the full rise to high frequencies. At the center the gain is $\sqrt{\alpha}$.
- [any] Not yet. Evaluate $|1 + j\omega/\omega_z|/|1 + j\omega/\omega_p|$ at $\omega_m$.
:::
:::

::: check
kind: parts
given: k = 3 | 5 | 10 | 20; P = 45 | 60

## A loop crosses over with a {P}° phase margin, and a PI zero is placed a factor {k} below the crossover.

::: part
answer: P - atan(1/k)*180/pi
unit: °
tolerance: 0.5%

### What phase margin remains?

::: misses
- [P - atan(k)*180/pi] The PI lags by $\tan^{-1}(\omega_z/\omega_c)$.
- [any] Subtract $\tan^{-1}(1/k)$.
:::
:::

::: part
answer: 20*log(sqrt(1 + 1/k^2))
unit: dB
tolerance: 1%

### How much does it raise the gain at the old crossover?

::: misses
- [any] $|1 + \omega_z/(j\omega_c)| = \sqrt{1 + 1/k^2}$.
:::
:::
:::

::: check
kind: derivation
vars: a = 1.5..100, w = 0.1..10000

## A lead with pole-to-zero ratio a is centered on frequency w.

::: step
answer: asin((a - 1)/(a + 1))*180/pi

### What is its maximum phase, in degrees?
:::

::: step
answer: w/sqrt(a)

### Where is its zero?
:::

::: step
answer: w*sqrt(a)

### And its pole?
:::

::: step
answer: 10*log(a)

### How many decibels above its DC gain is it at the center?
:::

::: right
Right. The geometric mean of zero and pole is where the phase peaks, and the gain there is halfway between the two levels in decibels.
:::
:::

::: explain
## Why is a lead compensator centered on the crossover frequency?

::: model
The lead exists to supply phase where the margin is measured, which is the crossover. Its phase bump peaks at the geometric mean of its zero and pole, so that's where it gives the most phase per unit of the high-frequency gain it adds. If the bump sits below the crossover, its phase is wasted at frequencies where the loop gain is already large; if it sits above, the crossover sees little of it. Putting the peak exactly at the intended crossover, and then setting the gain so the loop crosses there, gets the needed phase with the smallest α and so the least amplification of high-frequency noise.
:::
:::

::: practice

::: check
given: a = 3 | 8 | 15
answer: asin((a - 1)/(a + 1))*180/pi
unit: °
tolerance: 0.5%

## Lead's maximum phase for α = {a}?

::: misses
- [any] $\sin^{-1}\frac{\alpha - 1}{\alpha + 1}$.
:::
:::

::: check
given: f = 25 | 40 | 60
answer: (1 + sin(f*pi/180))/(1 - sin(f*pi/180))
tolerance: 0.5%

## α for {f}° of lead?

::: misses
- [any] $\frac{1 + \sin\phi}{1 - \sin\phi}$.
:::
:::

::: check
given: w = 5 | 100; z = 0.5 | 10; p = 0.05 | 2
answer: (atan(w/z) - atan(w/p))*180/pi
unit: °
tolerance: 0.5%

## Lag's phase at {w} rad/s, zero {z}, pole {p}?

::: misses
- [any] Zero's phase minus pole's.
:::
:::
:::
