Changing rate by a fraction: 44.1 kHz to 48 kHz
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
CD audio runs at 44,100 samples per second and video at 48,000. Their ratio is 160/147, so the conversion chains the two integer tools of this module: upsample by 160 (interpolation), low-pass filter once, and downsample by 147 (decimation). Follow a 1 kHz tone through the chain, see why one filter with cutoff 22.05 kHz does both anti-imaging and anti-aliasing, measure how close the new samples land on the tone, and see why a polyphase filter needs only about 0.96 million multiplies per second. Builds on the Decimation and Interpolation lessons, the DTFT and the windowed FIR design lesson.
Two rates that do not divide
A music CD stores 44,100 samples per second. Professional video uses 48,000. To play a CD track in a video we need samples at new instants, and 48,000 / 44,100 = 1.0884 is not a whole number.
input fs = 44,100 Hz (audio CD)
one sample every 22.68 µs
output fs = 48,000 Hz (professional video)
one sample every 20.83 µs
48000 / 44100 = 1.0884
not a whole number: we cannot just
repeat or drop samples
test signal: a 1 kHz tone, x[n] = sin(2π·1000·n / 44100)اقرأ الدرس خطوة بخطوة
Two rates that do not divide
A music CD stores 44,100 samples per second. Professional video uses 48,000. To play a CD track in a video we need samples at new instants, and 48,000 / 44,100 = 1.0884 is not a whole number.
input fs = 44,100 Hz (audio CD) one sample every 22.68 µs output fs = 48,000 Hz (professional video) one sample every 20.83 µs 48000 / 44100 = 1.0884 not a whole number: we cannot just repeat or drop samples test signal: a 1 kHz tone, x[n] = sin(2π·1000·n / 44100)A ratio of two whole numbers
Divide both rates by their greatest common divisor, 300: the ratio is 160/147. Every 147 input samples become exactly 160 output samples, and every 1/300 s = 3.33 ms the two grids of instants line up again.
gcd(48000, 44100) = 300 48000 / 300 = 160 = L (up) 44100 / 300 = 147 = M (down) 48000 / 44100 = 160 / 147 in 1/300 s = 3.33 ms: 147 input samples, 160 output samples dashed lines: the new instants m / 48000 s y[1] falls 0.919 of the way from x[0] to x[1]Step 1: upsample by L = 160
Put 159 zeros after every input sample. The rate becomes 44,100 × 160 = 7,056,000 samples per second: a fine grid that holds both the old and the new instants. The real samples are untouched.
upsampler (expander) ↑160: v[j] = x[j / 160] if j is a multiple of 160 v[j] = 0 otherwise fine rate = 44100 × 160 = 7,056,000 Hz = 7.056 MHz fine step = 1 / 7.056 MHz = 141.7 ns old instants: every 160 fine steps new instants: every 147 fine steps (drawn: a few of the 159 zeros)Zeros make images
Stuffing zeros keeps the spectrum's shape but reveals copies of it. Our 1 kHz tone now also appears at 44.1 ± 1 kHz, 88.2 ± 1 kHz and higher. These copies, called images, are not in the music and must go.
spectrum of the zero-stuffed signal: V(ω) = X(ω·160) the tone and its images (kHz): 1 (the tone) 43.1, 45.1, 87.2, 89.2 ... = k × 44.1 ± 1, up to 7.056 MHz / 2 plot: 0 to 100 kHz, every line height 1Step 2: one low-pass filter
A low-pass filter with cutoff 22.05 kHz removes every image: the one at 43.1 kHz drops by 78.6 dB. Its gain of 160 restores the level. In time, it fills the zeros with smooth values: interpolation.
filter h: 3201 taps at 7.056 MHz Kaiser window, β = 5 cutoff 22.05 kHz (gain halves there) gain 160 at 0 Hz size after the filter (1 = unchanged): 1.0 kHz 1.00e+0 (0.0 dB) 43.1 kHz 1.17e-4 (−78.6 dB) 45.1 kHz 1.54e-4 (−76.3 dB) 87.2 kHz 4.38e-6 (−107.2 dB) 89.2 kHz 1.77e-5 (−95.0 dB)Why the cutoff is 22.05 kHz
The filter has two jobs. It removes images above the input's Nyquist frequency, 22.05 kHz, and it stops anything above the output's Nyquist, 24 kHz, folding back (aliasing) at step 3. So its cutoff is the smaller: 22.05 kHz.
job 1, anti-imaging: cutoff π/L = π/160 = 7.056 MHz / 2 / 160 = 22.05 kHz job 2, anti-aliasing: cutoff π/M = π/147 = 7.056 MHz / 2 / 147 = 24.00 kHz one filter, cutoff min(π/L, π/M) = π/160 at 24 kHz this filter is 19.7 dB down. 48 kHz to 44.1 kHz: swap L and M; the cutoff is still 22.05 kHzStep 3: downsample by M = 147
Keep one fine sample in every 147 and drop the rest: 7,056,000 / 147 = 48,000 samples per second. Output y[m] is fine sample number 147·m, which sits at time m / 48,000 s.
downsampler (compressor) ↓147: y[m] = w[147·m] 7,056,000 / 147 = 48,000 Hz fine sample 147·m is at 147·m / 7,056,000 s = m / 48000 s y[0] = 0.0000 y[1] = 0.1281 y[2] = 0.2611 y[3] = 0.3802The same tone, new instants
The new samples sit on the same 1 kHz sine. y[1] = 0.1281; the true tone at 20.83 µs is 0.1305. The first 8 outputs are up to 0.0025 off, because the filter sees silence before x[0]. After that the error stays below 0.0007.
y[1] at t = 1 / 48000 s = 20.83 µs resampled 0.1281 true tone sin(2π·1000·20.83 µs) = 0.1305 largest error |y[m] − tone|: y[1] .. y[8] 0.0025 (start-up) from y[9] on 0.0007 the filter's ripple at 1 kHz: 0.0052 dBOnly compute what you keep
Done literally, the filter runs at 7.056 MHz over mostly zeros, then 146 of every 147 results are thrown away. A polyphase filter computes only the kept outputs, with only the 20 or 21 taps that land on real samples.
literal: every fine sample, every tap 7,056,000 × 3201 = 22.6 billion multiplies per second polyphase: only kept outputs, only taps on real samples (3201 / 160 ≈ 20-21) 48000 × 20.01 ≈ 0.96 million multiplies per second y[m] = Σ x[k] · h[1600 + 147·m − 160·k]In Python: resample_poly
scipy.signal.resample_poly(x, 160, 147) does all three steps with a polyphase filter. By default it designs the low-pass itself: 3,201 taps, a Kaiser window with β = 5, cutoff 1/160 of the fine Nyquist frequency.
import numpy as np from scipy.signal import resample_poly n = np.arange(44100) x = np.sin(2*np.pi*1000*n/44100) y = resample_poly(x, 160, 147) >>> len(y) 48000 >>> y[:4].round(4) array([0. , 0.1281, 0.2611, 0.3802]) (Python 3 with numpy and scipy)
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01Which pair (L, M) converts 44,100 Hz to 48,000 Hz with the smallest whole numbers?
48,000 / 44,100 = 480 / 441, and gcd(48,000, 44,100) = 300 reduces it to 160 / 147. Going up in rate means L (the upsampling factor) is the larger number. 480/441 is right but not reduced.
02What does inserting 159 zeros between samples do to the spectrum of the 1 kHz tone?
The zero-stuffed signal has spectrum X(ω·L): the original spectrum, squeezed, with its periodic copies now inside the fine band. Lines appear at 44.1 ± 1 kHz, 88.2 ± 1 kHz and so on; the low-pass filter must remove them.
03For 44.1 kHz to 48 kHz, which cutoff should the one low-pass filter have?
The cutoff is min(π/L, π/M) at the fine rate: π/160 is 22.05 kHz and π/147 is 24 kHz. The smaller one both removes the images and keeps anything that would alias at the downsampler out.
04Why must the filter's gain be L = 160?
After zero-stuffing, only one fine sample in 160 is non-zero, so after smoothing the tone comes out 160 times smaller. A gain of L puts it back at its original level; scipy builds this into the filter.
05Roughly how many multiplies per second does the polyphase resampler need for 48,000 outputs per second with a 3,201-tap filter?
Each output uses only the taps that land on real (non-zero) samples: 3,201 / 160 ≈ 20. So 48,000 × 20.006 ≈ 0.96 million. Filtering every fine sample with every tap would be 22.6 billion.
المسرد
- Sample-rate conversion (resampling)
- Computing the samples a signal would have had at a different sampling rate, without going back to analog.
- Rational factor L/M
- A rate change written as a ratio of two whole numbers with no common divisor, here 160/147.
- Upsampling (expander) ↑L
- Putting L − 1 zeros after each sample, so the rate rises by L. The real samples are unchanged.
- Image
- A copy of a signal's spectrum at a multiple of the old sampling rate that appears after upsampling and must be filtered out.
- Interpolation filter
- The low-pass filter after the upsampler; it removes the images and so fills the zeros with smooth values. Its gain is L.
- Downsampling (compressor) ↓M
- Keeping every M-th sample and dropping the rest, so the rate falls by M. Anything above the new Nyquist frequency would alias.
- Nyquist frequency
- Half the sampling rate: the highest frequency a sampled signal can hold without aliasing (22.05 kHz at 44.1 kHz, 24 kHz at 48 kHz).
- Polyphase filter
- An implementation that computes only the outputs that are kept, using only the taps that meet non-zero inputs.
الملاحظات والمصادر
- The tone is a chosen test signal at full scale 1. The filter is the one scipy.signal.resample_poly designs by default; every value in the figure is computed from it and matches scipy 1.18.1.
- The token streams are not to scale: after the upsampler only a few of the 159 zeros per sample are drawn, and the spectrum shows 0 to 100 kHz of a fine grid that reaches 3.528 MHz.
- Integer decimation and interpolation each have their own lesson in this module; this lesson chains them.
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed., §4.6 changing the sampling rate (course text on MIT OCW 6.341 readings)
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing (A. V. Oppenheim)
- SciPy documentation: scipy.signal.resample_poly (up, filter, down; default Kaiser window β = 5; zero padding)
- SciPy source: resample_poly filter design (f_c = 1/max_rate, half_len = 10·max_rate, firwin)
- SciPy documentation: scipy.signal.firwin
- SciPy documentation: scipy.signal.upfirdn (polyphase cost O(N/P) instead of O(N·Q))
- Sample-rate conversion (Wikipedia): 44.1 to 48 kHz with L = 160, M = 147, low-pass at 22.05 kHz
- 44,100 Hz (Wikipedia): the CD rate and its 147:160 ratio to 48 kHz
- Sampling (signal processing) (Wikipedia): 48 kHz is the standard rate of professional digital video
- Upsampling (Wikipedia): zero insertion, images, interpolation filter, polyphase
- Downsampling (Wikipedia): keep every M-th sample, aliasing, the lower of the two cutoffs
- NumPy documentation: numpy.arange
اختبار يتاح بعد الخطوة الأخيرة.