ENع
→The Nyquist rate
الدرس 09 · Sampling and conversion

The Nyquist rate

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

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

How often must you sample a wave to keep it? Follow a 1000 Hz tone through a converter whose clock you slow down: at 8000 and 2500 samples a second the numbers rebuild the tone exactly, at exactly 2000 it vanishes, and at 1500 it comes back as a false 500 Hz tone. You will see why in the spectrum, learn the rule fs > 2·fmax, and meet the Nyquist rate and the Nyquist frequency. It follows the lesson "Sampling: taking snapshots"; the Circuits lesson on filters helps for the last step.

ستتعلّم

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

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

A 1 kHz tone

A tone generator makes a 1000 Hz tone: x(t) = sin(2π·1000·t) volts. It repeats 1000 times a second, so one cycle lasts 1 ms. The question: how often must we measure it to keep it?

x(t) = sin(2π·f·t) V
  f = 1000 Hz (cycles per second)
  T = 1/f = 1 ms per cycle
  peak = 1 V

plot: 4 ms = 4 cycles

sampling = measuring x(t) at evenly spaced
instants (lesson "Sampling: taking snapshots")
motion in the figure: slowed down a lot
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. A 1 kHz tone

    A tone generator makes a 1000 Hz tone: x(t) = sin(2π·1000·t) volts. It repeats 1000 times a second, so one cycle lasts 1 ms. The question: how often must we measure it to keep it?

    x(t) = sin(2π·f·t) V
      f = 1000 Hz (cycles per second)
      T = 1/f = 1 ms per cycle
      peak = 1 V
    
    plot: 4 ms = 4 cycles
    
    sampling = measuring x(t) at evenly spaced
    instants (lesson "Sampling: taking snapshots")
    motion in the figure: slowed down a lot
  2. A clock sets the sampling rate

    A clock tells the converter (ADC) when to measure. At fs = 8000 samples a second it ticks every 125 µs: 8 samples in each 1 ms cycle. Each sample flies to memory as a number.

    fs = 8000 samples per second
    Ts = 1/fs = 125 µs between samples
    per cycle: fs / f = 8000 / 1000 = 8
    
    x[n] = x(n/fs) = sin(2π·1000·n/8000)
     x[0..4] = 0.00, 0.71, 1.00, 0.71, 0.00 V
  3. Rebuild the wave from the numbers

    Can the numbers alone give the wave back? A rebuilder (DAC) draws the smoothest wave through the dots: the one with no frequency above fs/2 = 4000 Hz. It lands exactly on the 1 kHz tone.

    rebuild (ideal DAC):
      r(t) = Σ x[n]·sinc(fs·t − n)
      sinc(u) = sin(πu) / (πu)
    
    the only wave through the dots
    with no frequency above fs/2
    
    fs/2 = 4000 Hz,  tone = 1000 Hz  ->  kept
    r(t) = x(t): the two curves overlap
    how real DACs do it: lesson "DACs and reconstruction"
  4. Slower: 2.5 samples a cycle

    Slow the clock to 2500 samples a second: only 2.5 samples per cycle. The dots look far too few, yet the smoothest wave through them is still exactly the 1 kHz tone.

    fs = 2500 /s,  Ts = 400 µs
    per cycle: 2500 / 1000 = 2.5
    
    x[0..4] = 0.00, 0.59, −0.95, 0.95, −0.59 V
    
    fs/2 = 1250 Hz > 1000 Hz  ->  kept
    rebuilt wave = the 1000 Hz tone
  5. The samples hold copies of the tone

    A spectrum shows which frequencies a signal holds. The samples hold the 1 kHz tone plus copies at fs ± 1 kHz: 1.5 kHz, 3.5 kHz and more. The rebuilder keeps only 0 to fs/2 = 1.25 kHz.

    samples taken fs times a second cannot
    tell f apart from k·fs ± f  (k = 1, 2, ...)
    
    fs = 2500 Hz, f = 1000 Hz:
      tone      1.0 kHz
      copies    1.5, 3.5, 4.0, 6.0, 6.5,
                8.5, 9.0 kHz ...
    
    rebuilder keeps 0 .. fs/2 = 1.25 kHz
      -> only the 1.0 kHz line: correct
  6. Exactly 2 a cycle: the tone vanishes

    At exactly 2000 a second, 2 samples per cycle, every tick here lands on a zero crossing. All samples read 0.00 and the rebuild is silence. The copy at fs − 1 kHz now sits on the tone and cancels it.

    fs = 2000 /s = 2·f
    x[n] = sin(2π·1000·n/2000) = sin(π·n) = 0
    
    x[0..4] = 0.00, 0.00, 0.00, 0.00, 0.00 V
    rebuilt: 0 V (silence)
    
    with another start time the dots land
    elsewhere: 2 per cycle cannot tell
    waves of different phase apart
  7. Too slow: a wrong, lower tone

    At 1500 a second (1.5 per cycle) the copy at fs − 1 kHz = 500 Hz falls below fs/2 = 750 Hz. The rebuilder plays a 500 Hz tone, not 1 kHz. This false tone is an alias.

    fs = 1500 /s,  fs/2 = 750 Hz < 1000 Hz
    
    x[0..4] = 0.00, −0.87, 0.87, 0.00, −0.87 V
    
    copy: fs − f = 1500 − 1000 = 500 Hz
    rebuilt: −sin(2π·500·t), a 500 Hz tone
    
    the same dots fit both waves
    aliasing: next lesson
  8. The Nyquist rate

    The rule: sample faster than twice the highest frequency in the signal, fs > 2·fmax. That limit, 2·fmax, is the Nyquist rate: 2000 a second for our tone. Half the sampling rate, fs/2, is the Nyquist frequency.

    sampling theorem (Shannon 1949):
      fs > 2·fmax  ->  samples keep everything
    
    Nyquist rate       = 2·fmax  (of the signal)
    Nyquist frequency  = fs/2    (of the sampler)
    
    our tone: fmax = 1000 Hz
      Nyquist rate = 2000 /s
      8000, 2500  ok      2000, 1500  fail
    
    strictly greater: = 2·fmax is not enough
  9. Real systems keep a margin

    Phone voice reaches about 3.4 kHz and is sampled 8000 times a second; its Nyquist rate is 6800. CDs cover hearing up to 20 kHz at 44,100 a second, above 40,000. The gap leaves room for a filter.

    signal         fmax      Nyquist rate   fs used
    phone voice    3.4 kHz   6800 /s        8000 /s
    CD audio       20 kHz    40,000 /s      44,100 /s
    
    the margin lets a real low-pass filter
    remove everything above fs/2 first
    (lesson "Anti-alias filters";
     filters in Circuits, "Filters")
  10. Check it in Python

    In Python with numpy, sample the tone at fs = 2000: n = np.arange(5), then x = np.sin(2*np.pi*f*n/fs). Every value is about 1e-16: zero plus floating-point rounding. The tone has vanished.

    import numpy as np
    f, fs = 1000, 2000
    n = np.arange(5)
    x = np.sin(2*np.pi*f*n/fs)
    
    >>> x.round(2)
    array([ 0.,  0., -0.,  0., -0.])
    >>> np.abs(x).max()
    np.float64(4.898587196589413e-16)
    
    try fs = 2500:
    array([ 0.  ,  0.59, -0.95,  0.95, -0.59])
    
    (Python 3 with numpy 2)

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