A sine goes in
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?
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 ...
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.
The frequency response
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.
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.
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|.
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.
Every 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.
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.
ω 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π).
In code
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].
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.