C9 · Lesson 23 · Digital processing of analog signals and changing the sample rate
Filters that run on samples, and moving between sample rates
Most filters today are a converter, a processor and another converter: sample the analog signal, run a difference equation, turn the result back into a voltage. Done right, the whole chain behaves exactly like an analog filter, and its cutoff moves when the sample rate does. Systems also have to move signals between rates all the time: audio recorded at 44.1 kHz and played at 48 kHz, a radio that samples fast and then works at a much slower rate. Dropping samples or inserting zeros sounds trivial, but each needs a filter, or aliases and images creep in.
- The dashed curve is a signal's spectrum, occupying low frequencies up to , plotted from 0 to π. The solid curve is the spectrum after inserting L − 1 zeros between every pair of samples.
- At L = 1 nothing changes. Raise L: the spectrum is squeezed toward 0 by a factor L, and copies, the images, appear at multiples of 2π/L.
- An interpolation filter keeps everything below the marker at π/L and removes the images; what's left is the same signal at L times the sample rate.
Predict
A signal sampled at 48 kHz contains a 10 kHz tone. Every fourth sample is kept, with no filter first. Where does the tone appear at the new rate?
2 kHz. The new rate is 12 kHz, whose Nyquist frequency is 6 kHz, so 10 kHz aliases to |10 − 12| = 2 kHz. A decimator must low-pass the signal to the new Nyquist frequency before throwing samples away.
Name it
Digital processing of analog signals
Sample at , filter with , convert back. For a band-limited input the chain acts like an analog filter with
So a digital cutoff is an analog cutoff , and the same coefficients at twice the sample rate cut off at twice the frequency.
Decimation by M
Keep every Mth sample: the rate becomes and frequencies are stretched by M, . Anything above beforehand aliases, so first low-pass to (the anti-aliasing step done digitally).
Interpolation by L
Insert L − 1 zeros after each sample: the spectrum is squeezed by L, , leaving L − 1 images in the band. A low-pass at with gain L removes them and fills in the missing samples.
Rational rate changes
Up by L, filter at the lower of the two cutoffs, down by M: the rate becomes . 44.1 kHz to 48 kHz is L/M = 160/147.
Oversampling
Sampling faster than needed relaxes the analog anti-aliasing filter (a wide guard band) and spreads the converter's quantization noise over a wider band: each doubling of the rate, filtered back down to the signal band, lowers the in-band noise by 3 dB, in all.
Worked example
A digital low-pass has . What analog cutoff does it give at 48 kHz and at 96 kHz?
Show the solution
- Map to analog frequency.
- At each rate. That's 6 kHz at 48 kHz and 12 kHz at 96 kHz.
- Keeping 6 kHz. To keep 6 kHz at the higher rate, the coefficients must be redesigned for .
Answer 6 kHz at 48 kHz and 12 kHz at 96 kHz.
Worked example
Convert 44.1 kHz audio to 48 kHz.
Show the solution
- Ratio in lowest terms.
- Upsample by 160. Insert 159 zeros between samples, which takes the rate to 7.056 MHz.
- Filter. Low-pass below 20 kHz or so, under both rates' Nyquist frequencies (22.05 kHz being the lower).
- Downsample by 147. Keep every 147th sample.
- In practice. A polyphase filter computes only the samples that are kept.
Answer upsample by 160, low-pass below about 20 kHz, then keep every 147th sample.
Worked example
A 1 kHz tone sampled at 8 kHz is upsampled by 3 (two zeros between samples). Where do images appear before the interpolation filter?
Show the solution
- New rate. The new rate is 24 kHz, so the spectrum now runs to a Nyquist frequency of 12 kHz.
- Images. Inserting zeros keeps the old spectrum and its copies around 8 kHz: below 12 kHz there are tones at 1, 7 and 9 kHz.
- The interpolation filter. It must keep 1 kHz and remove everything from 7 kHz up, which is why it's a low-pass with cutoff at the old Nyquist frequency, 4 kHz.
Answer images appear at 7 and 9 kHz, beside the 1 kHz tone.
Check
A digital filter's cutoff is ω = 0.5 rad. What analog cutoff does it give at 8 kHz?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
A signal at 48 kHz is decimated by 2.
(a)
What is the new sample rate?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
(b)
Below what ω (at the old rate) must the signal be filtered first?
Check
A 9 kHz tone at 48 kHz is decimated by 4 with no filter. At what frequency does it appear?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
A tone at ω = 0.6 is interpolated by inserting 2 − 1 zeros between samples.
(a)
Where is the tone after zero insertion?
Write units the way you normally would: 1.5 rad and 1500 mrad are the same answer.
(b)
Where is the lowest image?
Check
An 8 kHz signal is upsampled by 2 and then downsampled by 7. What is the final rate?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
A converter oversamples by 16 and filters back down to the signal band. By how many dB does the in-band quantization noise fall?
Check
Why does interpolation's low-pass filter need a gain of L?
Check
A 96 kHz signal is decimated by 2.
(a)
What is the new sample rate?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
(b)
Below what frequency must the anti-aliasing filter keep the signal?
Check
A 2 kHz tone sampled at 8 kHz is upsampled by 4.
(a)
Where is the lowest image the interpolation filter must remove?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
(b)
What is the new sample rate?
Explain why
Why must a decimator filter before it throws samples away, rather than after?
Keeping every Mth sample lowers the sample rate to , so frequencies between and no longer fit and fold down onto lower frequencies. Once they've folded, they sit on top of the wanted signal and can't be separated: the aliasing is permanent. Filtering first removes them while they're still at their own frequencies, distinct from the signal, so that what's left after dropping samples is only what the lower rate can represent.
Practice
Keep practicing
11 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.