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

C11 · Lesson 28 · Project: characterizing a filter from noisy data

Measuring a Bode plot and fitting its corner

A filter on the bench, a function generator on its input and a two-channel scope on its input and output: that's the setup for measuring a frequency response. At each frequency the scope captures a noisy record of both channels. A cursor reading of each trace's peak would be crude; a few lines of code give the amplitude and phase of each sine to a fraction of a percent, even through noise, by projecting each record onto a sine and cosine at the known frequency (lesson 16's lock-in, done in software). Then a least-squares fit turns a dozen noisy gain readings into one corner frequency. In this project you'll write all three steps.

  • The dots are six measured gains of an RC low-pass, each with a few tenths of a dB of noise. The curve is the first-order model −10log10⁡(1+(f/fc)2) for the corner you choose.
  • The readout is the sum of squared differences between the dots and the curve. Move fc to make it as small as you can: that's a least-squares fit, done by hand.
  • The best fit lands within a few hertz of the true 1.59 kHz, even though no single dot sits exactly on the true curve.

Predict

A filter's output measures −1.45 dB relative to its input at 1 kHz. If it's a first-order low-pass, where is its corner?

Name it

The pieces

Amplitude and phase by projection. Over a whole number of periods of frequency f, a record v(t) of N samples gives

a=2N∑vkcos⁡(2πftk),b=2N∑vksin⁡(2πftk)

and if v=Acos⁡(2πft+φ) plus noise and any DC, then a≈Acos⁡φ and b≈−Asin⁡φ:

A=a2+b2,φ=atan2⁡(−b,a)

The DC and the noise at other frequencies average out over whole periods.

A Bode point. With amplitude and phase for input and output at the same frequency, the gain is 20log10⁡(Aout/Ain) dB and the phase is φout−φin, wrapped into −180° to 180°.

The fit. For a first-order low-pass, G(f)=−10log10⁡(1+(f/fc)2). Choose fc to minimize ∑(Gi−G(fi))2. Search in ln⁡fc, since corners span decades: a coarse scan finds the valley, then golden-section search narrows it.

Single-point formulas

From one gain reading, fc=f/10−G/10−1; from one phase reading, fc=f/tan⁡(−φ). They're useful checks, but each rests on one noisy number.

Worked example

Projection of a record at 1 kHz gives a = 0.537 V and b = 0.273 V. What are the amplitude and phase?

Show the solution
  1. Amplitude. A=0.5372+0.2732V=0.602V
  2. Phase. φ=atan2⁡(−0.273,0.537)=−26.9°

Answer an amplitude of 0.602 V and a phase of −26.9°.

Worked example

A low-pass shows −32.1° of phase at 1 kHz. Where is its corner?

Show the solution
  1. Corner from the phase. fc=1000tan⁡32.1°Hz=1.59kHz This agrees with the gain reading.
  2. Where phase works best. Phase is most sensitive near the corner, where it changes fastest, so phase readings between 0.3 and 3 times fc give the best single-point estimates.

Answer the corner is at 1.59 kHz.

Check

A first-order low-pass measures −0.5 dB at 1000 Hz. Where is its corner?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

A first-order low-pass shows −15° of phase at 1000 Hz. Where is its corner?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

Projection gives a = 0.8 V and b = −0.6 V. What is the sine's amplitude?

Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.

Check

The input's amplitude is 1 V and the output's 0.05 V. What is the gain in dB?

Check

Write amp_phase(t, v, f): t and v are lists of sample times and values covering a whole number of periods of frequency f. Return (A, phi), the amplitude and phase (radians) of the component Acos⁡(2πft+φ), by projection.

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

Check

Write bode_point(t, vin, vout, f): return (gain_db, phase_deg) of the output relative to the input at frequency f, with the phase wrapped into −180° to 180°. Use your amp_phase (or the projection inside it).

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

Check

Write fit_corner(f, g): f is a list of frequencies and g the measured gains in dB of a first-order low-pass. Return the corner frequency fc that minimizes ∑(gi+10log10⁡(1+(fi/fc)2))2.

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

Explain why

Why does fitting a model to many gain readings give a better corner frequency than solving for it from the single reading nearest the corner?

Practice

Keep practicing

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