x[0]1.00x[1]0.71x[2]0.00x[3]−0.71x[4]−1.00×0.5DELAY0.71×0.5y[0]–y[1]–y[2]–y[3]–y[4]–1import numpy as np2from scipy.signal import freqz3w = [np.pi/4, np.pi]4_, H = freqz([0.5, 0.5], worN=w)5print(abs(H).round(3))6print(np.angle(H[0]))1000 Hz00000000
04812-1-0.500.51n (sample number)valuex[n] AND y[n]x[n] = cos(πn/4)y = 0.924·cos(πn/4 − π/8)x[n] = cos(πn) · y[n] = 000.511.5-0.500.5real partimaginary partH AS ARROWS0π/2π3π/22π00.51ω (rad per sample)|H|GAIN |H||H| = 0.924 at ω = π/40.707 (half power) at π/2|H| = 0 at ω = πmirror at π, repeats every 2πfreqz: 0.924 at π/4, 0 at π0π/2π3π/22π−90°−45°0°45°90°ω (rad per sample)∠H (degrees)PHASE ∠H∠H = −22.5° at ω = π/4∠H = −ω/2: a straight linejumps 180° where H = 0np.angle: −0.393 rad = −22.5°
Coloured parts: what the current step is about; everything else rests in whiteBlocks: input cells x[n], a junction, two ×0.5 blocks, the adder, the delay box, output cells y[n], the frequency dial and a Python code cardPlots: input and output against n, H as a sum of arrows, the gain |H| and the phase ∠H against ωValue tokens ride the wires one sample at a time; the dial pointer turns by ωThe two-point average y[n] = 0.5·x[n] + 0.5·x[n−1] has H(e^jω) = 0.5 + 0.5·e^(−jω) = e^(−jω/2)·cos(ω/2): gain 0.924 and phase −22.5° at ω = π/4 (1000 Hz at 8000 samples a second), gain 0 at ω = π. In the time plot the dots are the samples; the thin lines only join them along the sinusoid they lie on.

A sine goes in

  1. 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?

The frequency response

Every frequency

In code

The working

# step 1/11 · machine

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

The taps 0.5 and 0.5 and the rate of 8000 samples a second are chosen to keep the numbers short. Every value, curve and arrow in the figure is computed from this model. The input sine is taken to have been running forever, so the delay box already holds x[−1] = cos(−ω). A sine switched on at n = 0 gives one different first output (a short transient), then the same steady sine. In the time plot the dots are the samples; the thin lines only join them along the sinusoid they lie on.