ENع
→Resampling by L/M
الدرس 48 · Multirate and random signals

Changing rate by a fraction: 44.1 kHz to 48 kHz

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

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

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.

ستتعلّم

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

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

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)
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. 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)
  2. 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]
  3. 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)
  4. 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 1
  5. Step 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)
  6. 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 kHz
  7. Step 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.3802
  8. The 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 dB
  9. Only 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]
  10. 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)

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