S2 · Lesson 18 · Feedback lab
Loop gain, phase margin, step response and the nulling resistor, in Python
Stability analysis is where hand estimates and simulators most often disagree, because the estimates hide their approximations: "90° minus the arctangent" assumes the dominant pole is far below crossover, and "overshoot from phase margin" assumes a pure two-pole loop. This lab computes the exact numbers instead: it finds a two-pole loop's crossover and phase margin by bisection, simulates its closed-loop step response with Runge–Kutta to measure the real overshoot, and checks the right-half-plane zero that a nulling resistor moves.
- The curve is the closed-loop step response of a follower built from a two-pole amplifier (dominant pole far below, second pole at k times the gain-bandwidth), .
- At k = 2 the overshoot is 4.3%; at k = 1 it's 16%; at k = 4 the response is critically damped.
- The lab's simulation reproduces these values numerically from the loop's poles.
Predict
A follower uses an amplifier with , a dominant pole at 1 kHz and a second pole at 20 MHz. What phase margin does it have?
The exact crossover is where : about 9.1 MHz, not 10, since the second pole has already cut the gain by . The phase there is , a margin of 65.5°. The rule of thumb is pessimistic by 2°, and the gap grows as the poles approach.
Name it
The tools
- Loop gain: . The crossover solves (bisection in log f), and the phase margin is .
- Closed loop: with poles the follower obeys . Integrating it with RK4 gives the exact step response.
- Nulling resistor: in a Miller-compensated two-stage op amp, in series with moves the zero from to : infinity at , and into the left half plane beyond.
Check
Write phase_margin(A0, p1, p2, beta): return (phase margin in degrees, crossover frequency in Hz) for the two-pole loop, bisecting in log f between 1 Hz and Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write step_overshoot(A0, p1, p2, beta, n=200000): integrate the closed-loop equation from rest with a unit step input by RK4 over 20 natural periods ( with ) in n steps, and return the overshoot in percent over the final value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write rhp_zero(gm2, Cc, Rz): the compensation zero in rad/s (positive means right half plane), returning math.inf when exactly; and rz_for_cancel(gm2, Cc, p2): the that puts the zero on a left-half-plane pole at −p2 (rad/s).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write pm_rule(p2_over_ft): the rule-of-thumb phase margin for a second pole at k times the unity-gain frequency, and pm_error(A0, p1, k): the exact margin (from phase_margin with β = 1 and ) minus the rule's.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why is the phase-margin rule of thumb "90° minus arctan of the unity-gain frequency over the second pole" slightly pessimistic for a two-pole amplifier?
The rule assumes the loop gain crosses one at the gain-bandwidth frequency, as it would with only the dominant pole. But the second pole is already reducing the magnitude at that frequency, by a factor of , so the real crossover happens somewhat lower. At the lower frequency the second pole contributes less phase lag, so the actual margin is a little larger than the rule predicts. The difference is a couple of degrees when the second pole is twice the gain-bandwidth, and grows as the poles move closer together.