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 of , a resonator with = 1 rad/s.
- Lower and the peak grows taller and narrower, and moves toward .
- Above there's no peak at all: the gain falls steadily from 1.
Predict
A resonator with = 0.1 is driven at exactly . How large is its steady-state response compared with its response to a constant input of the same size?
Five times. At , , the quality factor . The true peak is a little higher and slightly below : at .
Name it
Frequency response
For , replacing by gives
Computing it on a grid of with NumPy's complex arithmetic gives the gain and phase everywhere at once. For the gain peaks at with height .
Convolution on a grid
With samples every , the integral becomes np.convolve(h, x)[:n] * dt. The error is proportional to for this simple rule.
Partial fractions from roots
For with distinct roots of , the residue at each root is , and
np.roots finds the and np.polyder gives . Complex roots come in conjugate pairs whose terms add to a real decaying sinusoid.
Worked example
Find the peak of for = 0.2 and = 1 rad/s.
Show the solution
- Peak frequency.
- Peak height.
- Check by sweep. A sweep over 300 000 points finds the same, 0.9592 rad/s and 2.5516.
- Compare with . At itself the gain is , 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 by residues.
Show the solution
- Output transform. so , with roots 0, and .
- Derivative of the denominator.
- Residues. They are , and :
- Evaluate at .
Answer , which is 0.200 at .
Check
At what frequency does the gain of a resonator with = 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
. What is the residue at ?
Check
Compute 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 from rest with RK4 ( = 0.001) to = 200 s. Set amp to the largest over the last 50 s, and phasor to .
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 is . On a grid with = 0.001 out to = 3, convolve it with a unit pulse lasting from 0 to 1, and set y2 to the result at = 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 for , by residues at the roots of (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 dB bandwidth of ( = 0.5) by bisecting on (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?
The phasor method assumes the system is linear, time-invariant and driven by a single sinusoid, and it gives only the final steady state. Inside those assumptions it's exact and instant, and a simulation can only approach it, after the transient dies and with a small enough step. Outside them, only simulation works: a nonlinear part (a diode, a saturating amplifier, a magnetic core) generates harmonics and makes the response depend on amplitude; an input that switches or isn't periodic has no single phasor; and if you need the start-up transient, the overshoot when a source turns on, the phasor method says nothing about it. Agreement between the two in the linear case is the check that makes the simulation trustworthy in the others.
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.