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

A8 · Lesson 34 · Lab: driven systems

Frequency response, convolution and partial fractions by computer

Lessons 26 to 33 gave three ways to find a driven system's response: phasors for the steady state, convolution with the impulse response for any input, and Laplace transforms with partial fractions for the whole solution. Each is a few lines of NumPy. In this lab you'll sweep a resonator's frequency response and find its peak, check the phasor prediction against a long simulation, convolve an impulse response with a pulse, and invert a Laplace transform from the roots of its denominator.

  • The curve is the gain |H(jω)| of y¨+2ζy˙+y=u, a resonator with ω0 = 1 rad/s.
  • Lower ζ and the peak grows taller and narrower, and moves toward ω0.
  • Above ζ=0.707 there's no peak at all: the gain falls steadily from 1.

Predict

A resonator with ζ = 0.1 is driven at exactly ω0. How large is its steady-state response compared with its response to a constant input of the same size?

Name it

Frequency response

For y¨+2ζω0y˙+ω02y=ω02u, replacing ddt by jω gives

H(jω)=ω02ω02−ω2+2jζω0ω

Computing it on a grid of ω with NumPy's complex arithmetic gives the gain and phase everywhere at once. For ζ<12 the gain peaks at ω01−2ζ2 with height 12ζ1−ζ2.

Convolution on a grid

With samples every Δt, the integral ∫0th(τ)x(t−τ)dτ becomes np.convolve(h, x)[:n] * dt. The error is proportional to Δt for this simple rule.

Partial fractions from roots

For Y(s)=N(s)D(s) with distinct roots pk of D, the residue at each root is rk=N(pk)D′(pk), and

y(t)=∑krkepkt

np.roots finds the pk and np.polyder gives D′. Complex roots come in conjugate pairs whose terms add to a real decaying sinusoid.

Worked example

Find the peak of |H(jω)| for ζ = 0.2 and ω0 = 1 rad/s.

Show the solution
  1. Peak frequency. ωp=1−2(0.04)=0.92=0.959rad/s
  2. Peak height. 12(0.2)0.96=2.55
  3. Check by sweep. A sweep over 300 000 points finds the same, 0.9592 rad/s and 2.5516.
  4. Compare with ω0. At ω0 itself the gain is 10.4=2.5, so the peak is only 2% higher: for light damping the distinction rarely matters.

Answer the peak is 2.55, at 0.959 rad/s.

Worked example

Find the step response of H(s)=1s2+3s+2 by residues.

Show the solution
  1. Output transform. Y(s)=1s(s2+3s+2) so D(s)=s3+3s2+2s, with roots 0, −1 and −2.
  2. Derivative of the denominator. D′(s)=3s2+6s+2
  3. Residues. They are 1D′(0)=12, 1D′(−1)=−1 and 1D′(−2)=12: y=12−e−t+12e−2t
  4. Evaluate at t=1. y(1)=0.5−0.368+0.068=0.200

Answer y=12−e−t+12e−2t, which is 0.200 at t=1.

Check

At what frequency does the gain of a resonator with ω0 = 1 rad/s and ζ = 0.2 peak?

Write units the way you normally would: 1.5 rad/s and 1500 mrad/s are the same answer.

Check

Y(s)=1(s+1)(s+2). What is the residue at s=−1?

Check

Compute |H(jω)|=1|1−ω2+2jζω| on a grid of 300 001 points from 0.01 to 3 rad/s for ζ = 0.2. Set w_peak and H_peak to the location and height of the maximum.

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

Check

Simulate y¨+0.4y˙+y=cos⁡0.8t from rest with RK4 (h = 0.001) to t = 200 s. Set amp to the largest |y| over the last 50 s, and phasor to 1|1−0.82+0.4⋅0.8j|.

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

Check

The impulse response of y˙+y=x is h=e−t. On a grid with Δt = 0.001 out to t = 3, convolve it with a unit pulse lasting from 0 to 1, and set y2 to the result at t = 2.

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

Check

Write step_response(den, t) returning y(t) for Y(s)=1s⋅den(s), by residues at the roots of s⋅den(s) (assume they're distinct). den is a coefficient list like [1, 3, 2]. Set y1 = step_response([1, 3, 2], 1.0).

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

Check

Find the −3 dB bandwidth of H=11−ω2+2jζω (ζ = 0.5) by bisecting |H(jω)|=12 on [0.01,10] (60 steps), and set w_bw.

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

Explain why

A simulation and the phasor method give the same steady-state amplitude. When would you trust only the simulation?

Practice

Keep practicing

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