S9 · Lesson 31 · Frequency-response lab
Evaluating loop transfer functions on the imaginary axis, counting Nyquist encirclements by phase unwrapping, finding the sensitivity peak, and computing the delay margin
Lessons 23 to 30 read stability and robustness off frequency responses: the Nyquist plot's encirclements, the margins, the sensitivity peak, how much delay a loop can swallow. Those plots are drawn by computers, and the numbers behind them come from a few simple routines: evaluate L(jω), track its phase without losing whole turns, search for peaks and crossings. In this lab you'll write them and check each against a result you can derive by hand.
- The curve is for the loop , with K on the slider.
- Below crossover |S| is small; near crossover it peaks, and the peak grows sharply as K approaches 8, the gain at which the Nyquist plot passes through −1.
- Above K = 8 the plot encircles −1 twice and the closed loop has two unstable poles, though |S| itself shows only a finite bump.
Predict
How many times does the Nyquist plot of encircle −1?
The plot crosses the negative real axis at (at ω = √3), so −1 lies inside the loop. Following ω from −∞ to ∞ the curve goes around it twice clockwise, and with no open-loop poles in the right half-plane, Z = N + P = 2 closed-loop poles are unstable. Your encirclement counter must find this from the phase of 1 + L alone.
Name it
What the lab computes
- L(jω) for given as coefficient lists, by Horner's rule on .
- Encirclements of −1: the net number of turns of around the origin as ω runs from −∞ to ∞, counted clockwise. For a stable, strictly proper L with real coefficients, the negative-frequency half mirrors the positive one, so it's twice the unwrapped phase change from ω ≈ 0 to ω → ∞, divided by −2π. Unwrapping means adding or subtracting 2π whenever consecutive samples jump by more than π.
- Sensitivity peak on a dense logarithmic grid.
- Delay margin: find the crossover where |L| = 1 by bisection in log ω, then PM/ω_c with PM in radians.
Check
Write freq_resp(num, den, w): L(jω) for coefficient lists (highest power first), and bode_point(num, den, w): its magnitude in dB and phase in degrees (principal value).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write encirclements(num, den): the net clockwise encirclements of −1 by the Nyquist plot of a stable, strictly proper L, by unwrapping the phase of 1 + L(jω) on 20 000 log-spaced frequencies from 10⁻⁴ to 10⁴ rad/s and doubling for the negative frequencies. Return a rounded integer.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write peak_sensitivity(num, den): on 20 000 log-spaced frequencies from 10⁻³ to 10³ 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 delay_margin(num, den): find the gain crossover by bisection on log ω between 10⁻⁴ and 10⁴ (assume |L| falls through 1 once), then return PM/ω_c in seconds, with the phase taken in (−360°, 0].
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why must a Nyquist encirclement count unwrap the phase rather than just look at where the plot ends?
The Nyquist plot starts and ends at known points, so its endpoints say nothing about how many times it went around −1 on the way. The count is the net number of full turns the vector from −1 to the curve makes, which is the total change of its angle divided by 2π. A computed angle is only known up to whole turns, jumping by 2π whenever it crosses the branch cut, so the code must follow it continuously from sample to sample, adding or subtracting 2π at each jump, and sample finely enough that the true angle never changes by more than half a turn between neighboring frequencies.