Anti-alias filters
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
A converter that samples 8000 times a second cannot tell frequencies apart above 4000 Hz: a 7500 Hz whistle folds down and lands at 500 Hz, and once it is in the samples nothing can take it out. The cure is a low-pass filter in front of the converter. Follow a 1000 Hz tone and a whistle through a 10 kΩ / 10 nF RC filter, see each bar of the spectrum shrink to the filter's gain, measure the leftover alias with a DFT, and compare a steeper 4th-order filter. It builds on the aliasing lesson and on the Circuits lesson "Passive and active filters".
A wanted tone and a whistle
A microphone picks up a 1 kHz tone we want and a loud 7.5 kHz whistle we do not. Each is a sine wave of 1 V. On the wire they add up: a slow wave covered in fast wiggles.
x(t) = sin(2π·1000·t) + sin(2π·7500·t) volts
wanted 1000 Hz, 1 V peak
whistle 7500 Hz, 1 V peak
left plot: the wave over time
right plot: its spectrum, one bar per
frequency (bar height = peak V)اقرأ الدرس خطوة بخطوة
A wanted tone and a whistle
A microphone picks up a 1 kHz tone we want and a loud 7.5 kHz whistle we do not. Each is a sine wave of 1 V. On the wire they add up: a slow wave covered in fast wiggles.
x(t) = sin(2π·1000·t) + sin(2π·7500·t) volts wanted 1000 Hz, 1 V peak whistle 7500 Hz, 1 V peak left plot: the wave over time right plot: its spectrum, one bar per frequency (bar height = peak V)The converter's limit: fs/2
The converter (ADC) takes fs = 8000 samples a second. It can only tell frequencies apart below half of that, fs/2 = 4 kHz: the Nyquist frequency. The 1 kHz tone fits. The 7.5 kHz whistle does not.
fs = 8000 samples per second (telephone rate) Ts = 1 / fs = 125 µs fs/2 = 4000 Hz (the Nyquist frequency) 1000 Hz < 4000 Hz fine 7500 Hz > 4000 Hz trouble why fs/2: see the aliasing lessonNo filter: the whistle folds down
With the switch closed, the filter is skipped and the converter samples the raw wave. The whistle folds back across 4 kHz to 8 − 7.5 = 0.5 kHz. The samples look like a 1 kHz tone plus a 500 Hz hum.
closed switch = a wire around R: no filtering at all alias: f -> fs − f (for fs/2 < f < fs) 7500 -> 8000 − 7500 = 500 Hz sin(2π·7500·n/8000) = −sin(2π·500·n/8000) for every whole n: same numbers samples s[0..4] (V): 0.00 0.32 0.29 −0.22 −1.00After sampling, there is no way back
In memory the alias is a real-looking 500 Hz tone of 1.00 V. A true 500 Hz sound could give the very same numbers, so no program can remove it later. The whistle must go before sampling.
DFT of 64 samples (bins of 125 Hz): 500 Hz 1.00 V <- the alias 1000 Hz 1.00 V <- the tone every other bin 0.00 the numbers carry no trace of 7500 Hz: sampling made the two tones identicalThe fix: a low-pass filter in front
Open the switch: now the signal passes resistor R, with capacitor C to ground. C lets fast changes leak away, so high frequencies shrink and low ones pass. A low-pass filter used this way is an anti-alias filter.
R = 10 kΩ in series, C = 10 nF to ground the ADC reads the voltage across C C's impedance 1/(2π·f·C) falls as f rises: 1000 Hz 15.9 kΩ 7500 Hz 2.1 kΩ RC low-pass in depth: Circuits, "Passive and active filters"The cutoff frequency
The filter's corner, or cutoff, is fc = 1/(2πRC). With R = 10 kΩ and C = 10 nF, fc = 1/(2π × 10 000 × 0.000 000 01) = 1592 Hz. At fc the gain is 1/√2 = 0.707.
fc = 1 / (2π·R·C) = 1 / (2π × 10e3 Ω × 10e-9 F) = 1591.5 Hz gain |H| = 1/√(1 + (f/fc)²) at f = fc: 1/√2 = 0.707 (−3 dB) the curve on the spectrum is |H(f)|Each tone gets its own gain
The 1 kHz tone keeps 0.85 of its size. The 7.5 kHz whistle shrinks to 0.21. Both started at 1 V, so each bar now ends on the curve. The price: the wanted tone loses a little too.
|H| = 1/√(1 + (f/fc)²) 1000 Hz: 1/√(1 + 0.628²) = 0.847 (−1.4 dB) 7500 Hz: 1/√(1 + 4.712²) = 0.208 (−13.7 dB) y(t) = 0.847·sin(2π·1000·t − 0.56 rad) + 0.208·sin(2π·7500·t − 1.36 rad)Sample the filtered wave
Now the converter samples the filtered wave. The whistle still folds to 500 Hz, but at 0.21 V instead of 1.00 V: a DFT of 64 samples finds 0.21 V at 500 Hz and 0.85 V at 1 kHz. Smaller, not gone.
DFT of 64 filtered samples: 500 Hz 0.21 V (was 1.00) 1000 Hz 0.85 V (was 1.00) alias down −13.7 dB samples s[0..4] (V): −0.65 −0.02 0.54 0.71 0.41Steeper filters, smaller aliases
One R and one C fall only 20 dB per decade. A 4th-order Butterworth filter with the same fc falls 80 dB per decade: it keeps 0.99 of the 1 kHz tone and leaves just 0.002 of the whistle.
n-th order Butterworth: |H| = 1/√(1 + (f/fc)^(2n)) falls 20·n dB per decade above fc 1st order 4th order 1000 Hz 0.847 0.988 7500 Hz 0.208 0.0020 another way out: sample much faster (oversampling), so a gentle filter has roomCheck it in Python
With numpy, three lines give the cutoff and both gains: fc = 1591.5 Hz, H = 0.847 and 0.208. np.sqrt works on the whole array at once. Change R or C and run it again.
import numpy as np fc = 1/(2*np.pi*10e3*10e-9) f = np.array([1000, 7500]) H = 1/np.sqrt(1+(f/fc)**2) >>> round(fc, 1) 1591.5 >>> H.round(3) array([0.847, 0.208]) (Python 3 with numpy)
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01A converter samples at 8000 samples per second. What is its Nyquist frequency?
The Nyquist frequency is half the sample rate: 8000 / 2 = 4000 Hz. Only frequencies below it can be told apart after sampling.
02With no filter, at fs = 8000 samples per second, where does a 7000 Hz tone appear in the samples?
7000 Hz is between fs/2 and fs, so it folds to fs − f = 8000 − 7000 = 1000 Hz.
03Why must the anti-alias filter come before the converter?
The whistle's samples are exactly the samples of a 500 Hz tone. A program only sees the numbers, so it cannot know which part was a whistle.
04An RC low-pass has R = 10 kΩ and C = 10 nF. What is its cutoff frequency?
fc = 1/(2πRC) = 1/(2π × 10 000 × 0.000 000 01) = 1591.5 Hz.
05A first-order filter passes the whistle with gain 0.21. What changes with a 4th-order Butterworth filter at the same cutoff?
|H| = 1/√(1 + (f/fc)^(2n)). With n = 4 the gain falls 80 dB per decade above fc instead of 20, so 7500 Hz drops to 0.002, and the 1 kHz tone, below fc, stays near 1.
المسرد
- Nyquist frequency
- Half the sample rate, fs/2. Only frequencies below it can be told apart after sampling.
- Alias
- A false lower frequency in the samples, made by a tone above fs/2. A tone at f between fs/2 and fs appears at fs − f.
- Anti-alias filter
- A low-pass filter placed before a converter so that frequencies above fs/2 are made small before sampling.
- Low-pass filter
- A circuit that passes slow (low-frequency) changes and shrinks fast (high-frequency) ones.
- Cutoff frequency fc
- The corner of a filter, where the gain has fallen to 1/√2 ≈ 0.707 (−3 dB); for an RC low-pass fc = 1/(2πRC).
- Gain |H(f)|
- How much of a sine wave at frequency f gets through: output amplitude divided by input amplitude.
- Filter order
- How many reactive parts (or poles) a filter has; each order adds 20 dB per decade to the fall above the cutoff.
- Oversampling
- Sampling much faster than the signal needs, so a gentle analog filter suffices and a digital filter does the sharp cut.
الملاحظات والمصادر
- Both tones are 1 V (a chosen example); 8000 samples a second is the telephone rate of ITU-T G.711, whose voice band is 300 to 3400 Hz, below the 4 kHz Nyquist frequency. The filtered wave is the steady state, after the switch-on transient (a few RC = 0.1 ms) has died away. Every number is computed from this model.
- The motion is slowed down a great deal: the real converter takes a sample every 125 µs.
- A first-order RC filter is the simplest anti-alias filter. Steeper filters (higher order) or a higher sample rate (oversampling, then a digital filter) give more room between the wanted band and fs/2.
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (ch. 7: sampling, aliasing)
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed. (course text listed on MIT OCW 6.341 readings)
- B. P. Lathi, R. A. Green, Linear Systems and Signals, Oxford University Press, 2018 (Internet Archive record)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011): sampling
- Nyquist–Shannon sampling theorem (Wikipedia): fs/2, aliases, low-pass filtering before sampling
- Anti-aliasing filter (Wikipedia): placed before the sampler; oversampling relaxes the analog filter
- Low-pass filter (Wikipedia): RC cutoff fc = 1/(2πRC), 20n dB per decade
- Butterworth filter (Wikipedia): gain 1/√(1 + (ω/ωc)^(2n))
- G.711 (Wikipedia): telephone audio sampled 8000 times a second, voice band 300–3400 Hz
- SciPy documentation: scipy.signal.butter (designing Butterworth filters)
- NumPy documentation: numpy.sqrt (element-wise)
- NumPy documentation: numpy.fft.fft (the discrete Fourier transform)
اختبار يتاح بعد الخطوة الأخيرة.