ENع
→Impulse response h[n]
الدرس 16 · Discrete-time signals and systems

The impulse response of a digital system

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

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

A digital system is a small program that turns one list of numbers into another. Feed it the unit impulse δ[n] and run it one sample at a time: what comes out is its impulse response h[n]. For the three-tap system y[n] = 0.5·x[n] + 0.3·x[n−1] + 0.2·x[n−2], h[n] is just its multipliers 0.5, 0.3, 0.2 (a finite impulse response). Because the system is linear and time-invariant, scaled and delayed impulses give scaled and delayed copies of h[n], so h[n] predicts the output for any input. Add feedback and h[n] goes on forever (an infinite impulse response); h[n] also tells you whether the system is stable. It builds on "Discrete-time signals x[n]" (δ[n] and sums of shifted impulses) and "System properties: linear, time-invariant, causal and stable".

ستتعلّم

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

شكل 16 · تفاعلي
01 / 09

A system is a small program

A digital system is a small program. It reads a list x[n] and writes a list y[n], one sample at a time. Ours is y[n] = 0.5·x[n] + 0.3·x[n−1] + 0.2·x[n−2]: it mixes the newest sample with the two before it.

system: a rule that turns one list into another

  y[n] = 0.5·x[n] + 0.3·x[n−1] + 0.2·x[n−2]

x[n−1], x[n−2]: the last two inputs,
  kept in a delay line (two memory cells)

it only ever looks at now and the past,
so it can run live, sample by sample
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. A system is a small program

    A digital system is a small program. It reads a list x[n] and writes a list y[n], one sample at a time. Ours is y[n] = 0.5·x[n] + 0.3·x[n−1] + 0.2·x[n−2]: it mixes the newest sample with the two before it.

    system: a rule that turns one list into another
    
      y[n] = 0.5·x[n] + 0.3·x[n−1] + 0.2·x[n−2]
    
    x[n−1], x[n−2]: the last two inputs,
      kept in a delay line (two memory cells)
    
    it only ever looks at now and the past,
    so it can run live, sample by sample
  2. Probe it with an impulse

    To learn what a system does, feed it the simplest input: the unit impulse δ[n], a single 1 at n = 0 and 0 everywhere else. Whatever comes out is called the impulse response, written h[n].

    x[n] = δ[n]
    
    n      −1   0   1   2   3   4   5
    δ[n]    0   1   0   0   0   0   0
    
    h[n] = the output when the input is δ[n]
    (the system starts at rest: all memory 0)
    
    like tapping a bell once and listening
  3. Run it one sample at a time

    Each tick, the delay line (cells that remember past samples) shifts right and the new sample enters. At n = 0 the 1 sits under ×0.5, so y[0] = 0.5. Next it moves under ×0.3, then ×0.2, then it falls off the end.

    n = −1: 0.5·0 + 0.3·0 + 0.2·0 = 0
    n =  0: 0.5·1 + 0.3·0 + 0.2·0 = 0.5
    n =  1: 0.5·0 + 0.3·1 + 0.2·0 = 0.3
    n =  2: 0.5·0 + 0.3·0 + 0.2·1 = 0.2
    n =  3: 0.5·0 + 0.3·0 + 0.2·0 = 0
    ...    0 from here on
    
    the single 1 visits each multiplier once
  4. h[n] is the list of multipliers

    So h[n] = 0.5, 0.3, 0.2, then zeros: exactly the three multipliers, in order. It ends after three samples, so this is a finite impulse response (FIR) system. And h[n] = 0 for n < 0: it never answers early (causal).

    h[n] = 0.5·δ[n] + 0.3·δ[n−1] + 0.2·δ[n−2]
    
    n      −1   0    1    2    3 ...
    h[n]    0  0.5  0.3  0.2   0 ...
    
    FIR: h[n] is zero after a finite length
      (3 taps -> 3 samples)
    causal: h[n] = 0 for every n < 0
      (output never comes before input)
  5. Scale and delay pass straight through

    Now feed 2δ[n−1]: twice as big, one step later. Out comes 2h[n−1] = 0, 1, 0.6, 0.4. Scaling passes through because the system is linear; the delay passes through because it is time-invariant (LTI).

    x[n] = 2·δ[n−1]
    
    n = 0: 0.5·0 + 0.3·0 + 0.2·0 = 0
    n = 1: 0.5·2 + 0.3·0 + 0.2·0 = 1
    n = 2: 0.5·0 + 0.3·2 + 0.2·0 = 0.6
    n = 3: 0.5·0 + 0.3·0 + 0.2·2 = 0.4
    
    y[n] = 2·h[n − 1]
    linear:          a·δ[n]   -> a·h[n]
    time-invariant:  δ[n − k] -> h[n − k]
    (see "System properties")
  6. Any input: add up shifted copies

    Any input is a sum of scaled, shifted impulses, so the output is the same sum of shifted copies of h[n]. For x = 1, 2: y = h[n] + 2h[n−1] = 0.5, 1.3, 0.8, 0.4. That sum is convolution, the next lesson.

    x[n] = 1·δ[n] + 2·δ[n−1]
    
             n:  0    1    2    3
      1·h[n]   : 0.5  0.3  0.2  0
      2·h[n−1] : 0    1    0.6  0.4
                 ---  ---  ---  ---
      y[n]     : 0.5  1.3  0.8  0.4
    
    y[n] = Σ x[k]·h[n − k]   (convolution)
    so h[n] tells you the output for ANY input
  7. Feedback: an infinite response

    Change the program to feed its own output back into the delay line: y[n] = x[n] + 0.5·y[n−1]. Now h[n] = 1, 0.5, 0.25, 0.125 ... = 0.5ⁿ for n ≥ 0. It shrinks but never becomes exactly zero: an infinite impulse response (IIR).

    y[n] = x[n] + 0.5·y[n−1]   (feedback)
    
    n = 0: 1 + 0.5·0     = 1
    n = 1: 0 + 0.5·1     = 0.5
    n = 2: 0 + 0.5·0.5   = 0.25
    n = 3: 0 + 0.5·0.25  = 0.125
    
    h[n] = 0.5ⁿ·u[n]  (an exponential)
    IIR: never exactly 0, however long you wait
    cells show 3 decimals (0.0625 -> 0.063)
  8. Stable if Σ|h[n]| is finite

    h[n] also shows stability: bounded inputs give bounded outputs exactly when Σ|h[n]| is finite. The FIR gives 0.5 + 0.3 + 0.2 = 1. The IIR gives 1 + 0.5 + 0.25 + ... = 2. Feedback 1.5 gives 1.5ⁿ: unstable.

    BIBO stable  <=>  Σ |h[n]| < ∞
    
    FIR:  0.5 + 0.3 + 0.2 = 1
          (every FIR is stable: finite sum)
    IIR:  1 + 0.5 + 0.25 + ... = 1/(1 − 0.5) = 2
    
    y[n] = x[n] + 1.5·y[n−1]:
      h[n] = 1.5ⁿ = 1, 1.5, 2.25, 3.375 ...
      Σ grows without limit: unstable
    rule for this IIR: |feedback| < 1
  9. In Python: lfilter

    In Python with numpy and scipy, make δ[n] as zeros with a 1 first, list the multipliers b, then run the system with scipy.signal.lfilter. It prints 0.5, 0.3, 0.2 and then zeros: the impulse response, as an array.

    import numpy as np
    import scipy.signal as sg
    d = np.zeros(7); d[0] = 1
    b = [0.5, 0.3, 0.2]
    h = sg.lfilter(b, [1], d)
    
    >>> print(h)
    [0.5 0.3 0.2 0.  0.  0.  0. ]
    
    lfilter(b, a, x):
      a[0]·y[n] = b[0]·x[n] + b[1]·x[n−1] + ...
                  − a[1]·y[n−1] − ...
    >>> print(sg.lfilter([1], [1, -0.5], d))   # IIR
    [1.       0.5      0.25     0.125    0.0625   0.03125  0.015625]
    
    (Python 3, numpy + scipy)

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