ENع
→The DTFT
الدرس 26 · From the DTFT to the FFT

The DTFT: the spectrum of a sampled signal

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

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

The discrete-time Fourier transform (DTFT) gives the spectrum of a sampled signal: X(e^jω) = Σ x[n]·e^(−jωn). Watch it work on four samples of a pulse. For one test frequency ω, every sample turns into an arrow; the arrows are added head to tail, and the length of the sum says how much of that frequency the signal holds. Sweep ω and the lengths draw the spectrum, which repeats every 2π, just like the spectrum copies from sampling. It builds on "Sampling in the frequency domain: spectrum copies" and reads e^(−jωn) as the spinning arrow from "Complex exponentials: growing, decaying and spinning" (complex numbers are in the Maths lessons); it ends with numpy and points to the DFT.

ستتعلّم

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

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

Four samples of a pulse

A converter samples a short pulse 8000 times a second. We keep four samples: x[0] to x[3] are all 1, and every other x[n] is 0. The pulse lasts 4/8000 s = 0.5 ms.

x[n] = 1   for n = 0, 1, 2, 3
x[n] = 0   for every other n

fs = 8000 samples per second
4 samples × 1/8000 s = 0.5 ms

question: which frequencies
make up this pulse?
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Four samples of a pulse

    A converter samples a short pulse 8000 times a second. We keep four samples: x[0] to x[3] are all 1, and every other x[n] is 0. The pulse lasts 4/8000 s = 0.5 ms.

    x[n] = 1   for n = 0, 1, 2, 3
    x[n] = 0   for every other n
    
    fs = 8000 samples per second
    4 samples × 1/8000 s = 0.5 ms
    
    question: which frequencies
    make up this pulse?
  2. Pick a test frequency ω

    The spectrum says how much of each frequency a signal holds. We test one frequency at a time. For samples, frequency ω is measured in radians per sample: ω = 2π·f/fs. Here ω = π/4, which is 1000 Hz.

    ω = 2π · f / fs     (radians per sample)
    
    ω = π/4 = 0.785 rad/sample
    f = ω · fs / 2π = 8000 / 8 = 1000 Hz
    
    radian: the angle where the arc
    equals the radius; π rad = 180°
    so π/4 = 45° per sample
  3. e^−jωn: an arrow that turns

    For each n, e^(−jωn) = cos(ωn) − j·sin(ωn). That is an arrow of length 1 at angle −ωn. From one sample to the next it turns by ω. At ω = π/4 the arrows point to 0°, −45°, −90° and −135°.

    e^(−jθ) = cos θ − j sin θ   (Euler)
    length 1, angle −θ
    
    n = 0:  angle    0°  ->  1
    n = 1:  angle  −45°  ->  0.71 − 0.71j
    n = 2:  angle  −90°  ->  −j
    n = 3:  angle −135°  -> −0.71 − 0.71j
    
    spinning arrows: see "Complex exponentials:
    growing, decaying and spinning";
    complex numbers: the Maths lessons
  4. Multiply each sample by its arrow

    Each sample scales its own arrow: x[n]·e^(−jωn). A bigger sample makes a longer arrow; a zero sample makes no arrow at all. All four samples here are 1, so every arrow keeps length 1.

    term n = x[n] · e^(−jωn)
    
    x[0..3] = 1  ->  arrows unchanged
    x[n] = 0 elsewhere -> no arrow
    
    so the sum has only four terms,
    though it runs over every n
  5. Add the arrows head to tail

    Add the arrows by placing each one where the last one ends. The sum is the DTFT at this ω: X(e^jπ/4) = 1.00 − 2.41j. Its length, |X| = 2.61, says how much of 1000 Hz the pulse holds.

    X(e^jω) = Σ x[n] · e^(−jωn)
    
    X(e^jπ/4) = 1 + (0.71 − 0.71j)
              + (−j) + (−0.71 − 0.71j)
              = 1.00 − 2.41j
    
    |X| = 2.613     (the length)
    angle = −67.5°   (the phase)
  6. ω = 0: all arrows agree

    Turn the test frequency down to ω = 0. Every arrow now points the same way, so they add up fully: X(e^j0) = x[0] + x[1] + x[2] + x[3] = 4. A pulse holds a lot of the slowest frequencies.

    ω = 0:  e^(−j·0·n) = 1 for every n
    
    X(e^j0) = Σ x[n] = 1 + 1 + 1 + 1
            = 4.00
    
    the largest |X| can be here:
    all four arrows are aligned
  7. ω = π/2: the arrows cancel

    At ω = π/2 (2000 Hz) the arrows turn 90° each time: right, down, left, up. Head to tail they close a square and end where they began. The sum is 0: this pulse holds none of 2000 Hz.

    ω = π/2 = 90° per sample
    
    1 + (−j) + (−1) + (+j) = 0
    
    X(e^jπ/2) = 0.00
    
    a zero of the spectrum:
    the arrows cancel exactly
  8. Sweep ω: the spectrum

    Now sweep ω from −π to π and plot the length |X| each time. The result is the spectrum of the pulse: tall at ω = 0, zero at ±π/2 and ±π. The DTFT gives a value at every ω, not just a few.

    |X(e^jω)| = |sin(2ω) / sin(ω/2)|
    (the sum of four arrows, in closed form)
    
    ω = 0     |X| = 4.00
    ω = π/4   |X| = 2.61
    ω = π/2   |X| = 0.00
    ω = π     |X| = 0.00
    
    ω is a real number: X is a
    continuous function of ω
  9. It repeats every 2π

    Keep turning past π. Since n is a whole number, adding 2π to ω turns each arrow by whole circles, so nothing changes. The DTFT repeats every 2π: the spectrum copies sampling makes. Only −π to π (±4000 Hz) is new.

    e^(−j(ω+2π)n) = e^(−jωn) · e^(−j2πn)
                  = e^(−jωn)     (n whole)
    
    so X(e^j(ω+2π)) = X(e^jω)
    
    ω = π  <->  f = fs/2 = 4000 Hz
    ω = 2π <->  f = fs   = 8000 Hz
    
    see "Sampling in the frequency domain:
    spectrum copies"
  10. The DTFT in Python

    With numpy (Python 3) the sum is one line: np.exp makes the arrows and np.sum adds them. A computer can only try a finite list of ω values. Choosing them well is the DFT, the next lesson.

    import numpy as np
    x, n = np.ones(4), np.arange(4)
    w = np.pi / 4
    X = np.sum(x * np.exp(-1j*w*n))
    
    >>> print(np.round(X, 2))
    (1-2.41j)
    >>> print(abs(X))
    2.613125929752753
    
    # many ω at once:
    w = np.linspace(-np.pi, np.pi, 801)
    X = np.exp(-1j*np.outer(w, n)) @ x

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