ENع
→Anti-alias filters
الدرس 11 · Sampling and conversion

Anti-alias filters

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

12 دقيقة10 خطوات5 أسئلةBeginner
عن هذا الدرس

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".

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 11 · تفاعلي
01 / 10

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)
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. 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)
  2. 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 lesson
  3. No 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.00
  4. After 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 identical
  5. The 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"
  6. 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)|
  7. 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)
  8. 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.41
  9. Steeper 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 room
  10. Check 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)

اختبار يتاح بعد الخطوة الأخيرة.