A1025 of 28
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A10 · Lesson 25 · Lab: Laplace and Bode in code

Poles, Bode plots, margins and responses by computer

Lessons 18 to 24 described systems by their transfer functions: poles and zeros, Bode plots, impulse and step responses. A transfer function is just two polynomials, and NumPy handles polynomials directly. In this lab you'll compute a Bode plot and read a feedback loop's crossover and phase margin from it, measure how far the straight-line asymptotes miss, find an RLC filter's poles and damping from its polynomial, invert a transform with complex poles and check it by simulation, and compute a pulse response by convolution.

  • The curves are the gain in dB of H(s)=K(s+10)(s+100) against log10⁡ω, and its straight-line asymptotes.
  • Raise K: the curve moves up and crosses 0 dB at a higher frequency, where the two poles have used up more phase.
  • The readout gives the phase margin at the crossover, which falls as K rises: more gain means a less damped closed loop.

Predict

At a single pole's corner frequency, how far below the straight-line asymptotes is the true gain?

Name it

Transfer functions as polynomials

Store numerator and denominator coefficients highest power first: s+3s2+3s+2 is num = [1, 3], den = [1, 3, 2]. Then:

  • np.polyval(num, s) / np.polyval(den, s) evaluates H(s) at any complex s, so H(jω) on a frequency grid gives the Bode plot;
  • np.roots(den) gives the poles, and np.roots(num) the zeros;
  • residues N(p)D′(p) at each simple pole give the impulse response ∑rkepkt.

Margins

For a loop gain L(s), the gain crossover is where |L(jω)|=1; the phase margin is 180° plus the phase there. A phase margin of 45° to 60° gives a well-damped closed loop; near 0° it rings and nearly oscillates.

Second-order poles

s2+2ζω0s+ω02 has poles at −ζω0±jω01−ζ2. From computed poles: ω0=|p| and ζ=−Rep|p|.

Worked example

Find the gain crossover and phase margin of L(s)=10000(s+10)(s+100).

Show the solution
  1. Set the gain to 1. |L(jω)|=1 means (ω2+100)(ω2+10000)=108
  2. Solve for the crossover. That's a quadratic in ω2, with root ω2=6108, so ωc=78.2rad/s
  3. The phase there. ϕ=−tan−1⁡7.82−tan−1⁡0.782=−82.7°−38.0°=−120.7°
  4. The phase margin. 180°−120.7°=59.3° a comfortable loop.

Answer the gain crossover is at 78.2 rad/s, and the phase margin is 59.3°.

Worked example

A series RLC has R = 100 Ω, L = 10 mH and C = 1 µF, with the output across C. Find its poles, ω0 and ζ.

Show the solution
  1. The transfer function. H=1LCs2+RCs+1
  2. Normalize the denominator. Dividing by LC gives s2+104s+108
  3. The poles. Its roots are −5000±j8660 s⁻¹, at distance 104 from the origin.
  4. The natural frequency. It's that distance: ω0=104rad/s
  5. The damping ratio. ζ=500010000=0.5
  6. The overshoot. The step response overshoots by e−π×0.5/0.866=16%

Answer poles at −5000±j8660 s⁻¹, ω0=104 rad/s and ζ=0.5; the step response overshoots by 16%.

Check

A single pole 11+s/ωc. What is its exact gain at 1 times its corner frequency?

Check

A series RLC with R = 100 Ω, L = 10 mH and C = 1 µF. Computing its poles p, what is −Rep/|p|?

Check

For L(s)=10000(s+10)(s+100), compute |L(jω)| and its phase on 200 001 log-spaced points from 1 to 10 000 rad/s. Set wc to the frequency where the gain is closest to 1 and pm to the phase margin there, in degrees.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

For a single pole 11+jω, set err1 and err2 to the exact gain minus the asymptote, in dB, at ω = 1 and 2 (the asymptote is 0 dB below the corner and −20log10⁡ω above).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

For the RLC with R = 100 Ω, L = 10 mH, C = 1 µF (output across C), find the poles of LCs2+RCs+1 with np.roots and set w0 and zeta from them.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Invert Y(s)=5s(s2+2s+5) by residues at the roots of its denominator (they include a complex pair) and set y1 to y(1). Then simulate y¨+2y˙+5y=5 from rest with RK4 (h = 0.001) and set y1_sim.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

An RC low-pass with τ = 1 ms gets a 1 V pulse lasting 2 ms. Convolve its impulse response h=1τe−t/τ with the pulse on a grid of Δt = 0.001 ms out to 6 ms, and set v2 and v4 to the output at 2 and 4 ms.

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 a phase margin of about 60° considered safe for a feedback loop, and what goes wrong as it shrinks?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.