ENع
→Frequency response
الدرس 27 · From the DTFT to the FFT

Frequency response H(e^jω)

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

14 دقيقة11 خطوة5 أسئلةIntermediate
عن هذا الدرس

Feed a sine into a linear, time-invariant system and a sine of the same frequency comes out, only scaled and shifted. The frequency response H(e^jω) says by how much, for every frequency. Follow a two-point average, y[n] = 0.5·x[n] + 0.5·x[n−1]: at ω = π/4 it passes 0.924 of the sine and delays it half a sample; at ω = π it cancels the sine completely. You will build H as a sum of arrows, read its gain and phase, see why it repeats every 2π, and compute it with scipy. It builds on the DTFT lesson, the impulse response lesson and complex exponentials.

ستتعلّم

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

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

A two-point average

This system averages each new sample with the one before: y[n] = 0.5·x[n] + 0.5·x[n−1]. A delay box keeps the previous input. Its impulse response is h = [0.5, 0.5]. What does it do to each frequency?

y[n] = 0.5·x[n] + 0.5·x[n−1]

impulse response  h[0] = 0.5, h[1] = 0.5
(finite: an FIR system, linear and
 time-invariant: LTI)

parts:
  delay   remembers x[n−1] for one tick
  ×0.5    two multipliers (the taps)
  +       the adder
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. A two-point average

    This system averages each new sample with the one before: y[n] = 0.5·x[n] + 0.5·x[n−1]. A delay box keeps the previous input. Its impulse response is h = [0.5, 0.5]. What does it do to each frequency?

    y[n] = 0.5·x[n] + 0.5·x[n−1]
    
    impulse response  h[0] = 0.5, h[1] = 0.5
    (finite: an FIR system, linear and
     time-invariant: LTI)
    
    parts:
      delay   remembers x[n−1] for one tick
      ×0.5    two multipliers (the taps)
      +       the adder
  2. Feed it a sine

    Feed it x[n] = cos(ω·n) with ω = π/4 radians per sample: 1000 Hz at 8000 samples a second. Each tick, x[n] and the stored x[n−1] are halved and added: y = 0.85, 0.85, 0.35, −0.35 ...

    x[n] = cos(π/4 · n)   (has run forever,
                           so the delay holds x[−1])
    
    n   x[n]    x[n−1]   y[n]
    0   1.00    0.71     0.85
    1   0.71    1.00     0.85
    2   0.00    0.71     0.35
    3   −0.71   0.00     −0.35
    4   −1.00   −0.71    −0.85
    
    ω in radians per sample;  f = ω·fs/2π
    π/4 × 8000 / 2π = 1000 Hz
  3. Out comes the same sine

    The output is a sine of the same frequency. Only two things changed: it is smaller (peak 0.924 instead of 1) and later (shifted by half a sample). A sine into an LTI (linear, time-invariant) system gives a sine out.

    x[n] = cos(π/4 · n)
    y[n] = 0.924 · cos(π/4 · n − π/8)
    
    same frequency π/4
    height × 0.924
    shifted by π/8 rad = half a sample
    
    check n = 0:  0.924 × cos(−π/8) = 0.85
  4. Why: a spinning arrow goes in

    Use the spinning arrow e^(jωn) = cos ωn + j·sin ωn. Delaying it one sample turns it back by ω: e^(jω(n−1)) = e^(jωn)·e^(−jω). So y[n] = (0.5 + 0.5·e^(−jω))·e^(jωn): the same arrow, times one number.

    input   x[n]   = e^(jωn)
    delayed x[n−1] = e^(jω(n−1)) = e^(jωn)·e^(−jω)
    
    y[n] = 0.5·e^(jωn) + 0.5·e^(jωn)·e^(−jω)
         = (0.5 + 0.5·e^(−jω)) · e^(jωn)
                ^ one complex number
    
    e^(jωn) comes out unchanged in shape:
    an eigenfunction of every LTI system
    cos ωn = (e^(jωn) + e^(−jωn)) / 2
  5. H is a sum of arrows

    That number is the frequency response: H(e^jω) = Σ h[k]·e^(−jωk). Add one arrow per tap: 0.5 at angle 0, then 0.5 turned by −ω. At ω = π/4 the sum ends at 0.854 − 0.354j.

    H(e^jω) = Σ h[k]·e^(−jωk)
            = 0.5 + 0.5·e^(−jω)
    
    ω = π/4:
      0.5·e^(−jπ/4) = 0.354 − 0.354j
      H = 0.5 + 0.354 − 0.354j
        = 0.854 − 0.354j
    
    this sum is the DTFT of h[n]
  6. Gain: the length |H|

    The length of H is the gain: |H(e^jω)| = |cos(ω/2)|. At ω = π/4 it is 0.924, so a sine of height 1 comes out with height 0.924. The output amplitude is the input amplitude times |H|.

    |H| = √(0.854² + 0.354²) = 0.924
    
    closed form: 0.5 + 0.5·e^(−jω)
               = e^(−jω/2)·cos(ω/2)
    so |H(e^jω)| = |cos(ω/2)|
       cos(π/8) = 0.924
    
    in decibels: 20·log10(0.924) = −0.69 dB
  7. Phase: the angle ∠H

    The angle of H is the phase shift: ∠H = −ω/2 = −π/8 rad = −22.5°. The output sine is shifted back by 22.5°. Here that is a delay of half a sample (62.5 µs) at every frequency.

    ∠H = atan2(−0.354, 0.854) = −0.393 rad
       = −π/8 = −22.5°
    
    from e^(−jω/2)·cos(ω/2):
      ∠H = −ω/2  (for |ω| < π)
    
    delay = −∠H / ω = 0.5 sample
          = 0.5 / 8000 s = 62.5 µs
    phase straight in ω: linear phase
  8. Sweep the frequency

    Turn the frequency from 0 to π. At ω = 0 (a constant) the arrows line up: gain 1. As ω rises, the second arrow swings away and the gain falls; half the power is lost at π/2. This average is a low-pass filter.

    ω       f (Hz)   |H|     ∠H
    0       0        1.000   0°
    π/4     1000     0.924   −22.5°
    π/2     2000     0.707   −45.0°
    3π/4    3000     0.383   −67.5°
    π       4000     0       (no angle)
    
    half power: |H|² = 0.5 at ω = π/2 (−3 dB)
    low frequencies pass, high ones are cut
  9. At ω = π the output is zero

    At ω = π (4000 Hz) the input flips sign every sample: 1, −1, 1, −1. Each sample plus the one before is 0, so y[n] = 0. The two arrows point opposite ways and cancel: |H(e^jπ)| = 0.

    x[n] = cos(π·n) = 1, −1, 1, −1 ...
    y[n] = 0.5·x[n] + 0.5·x[n−1] = 0
    
    H(e^jπ) = 0.5 + 0.5·e^(−jπ)
            = 0.5 − 0.5 = 0
    
    π rad per sample = fs/2 = 4000 Hz:
    the fastest a sampled sine can swing
  10. It repeats every 2π

    ω and ω + 2π give the same samples, because e^(j2πn) = 1. So H repeats every 2π. With a real h[n], |H| is mirror-symmetric, so 0 to π (0 to fs/2) tells everything. In hertz: f = ω·fs/(2π).

    e^(j(ω+2π)n) = e^(jωn)·e^(j2πn) = e^(jωn)
    so H(e^j(ω+2π)) = H(e^jω)
    
    real h[n]:  H(e^−jω) = H(e^jω)*  (conjugate)
      |H| even, ∠H odd
    
    ω = 2π − π/4 = 7π/4 acts like −π/4:
      |H| = 0.924, ∠H = +22.5°
    
    f = ω·fs/2π:  π -> 4000 Hz,  2π -> 8000 Hz
  11. In Python: scipy's freqz

    In Python 3, scipy.signal.freqz evaluates H(e^jω) = Σ b[k]·e^(−jωk) at the frequencies w. abs(H) gives the gains [0.924, 0]; np.angle gives the phase, −0.393 rad. H is the DTFT of h[n].

    import numpy as np
    from scipy.signal import freqz
    w = [np.pi/4, np.pi]
    _, H = freqz([0.5, 0.5], worN=w)
    print(abs(H).round(3))
    print(np.angle(H[0]))
    
    prints:
    [0.924 0.   ]
    -0.39269908169872414
    
    (numpy 2.5.4, scipy 1.18.1)
    freqz's default fs = 2π: w in rad/sample
    pass fs=8000 to work in hertz instead

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