h[n]1 · 0.5 · 0.25x[−2]0x[−1]0x[0]1x[1]2x[2]3x[3]0x[4]0y[0]–y[1]–y[2]–y[3]–y[4]–1import numpy as np2x = np.array([1, 2, 3])3h = np.array([1, 0.5, 0.25])4y = np.convolve(x, h)5print(y)h[2]0.25h[1]0.5h[0]10
-3-2-10123450123kvalueINPUT AXIS k-1012345601234nvalueOUTPUT y[n]1·h[n]2·h[n − 1]3·h[n − 2]
Coloured parts: what the current step is about; everything else rests in whiteBlocks: the echo system h, the input list x[k], the output list y[n] and a Python code cardPlots: the input axis k (x and the sliding h[n − k]) and the output axis n (copies stacking into y)The flipped window slides one step per output; each sum drops into its output cellAn echo with impulse response h = [1, 0.5, 0.25] turns the input x = [1, 2, 3] into y = x ∗ h = [1, 2.5, 4.25, 2, 0.75]. np.convolve defaults to mode "full" (length N + M − 1 = 5 here). mode "same" keeps the middle max(N, M) values and mode "valid" only the values where the two lists overlap completely (here just y[2] = 4.25).

The system and its input

  1. This digital system is an echo. Feed it one sample of 1, the impulse δ[n], and out comes 1, then 0.5, then 0.25. That list is its impulse response: h = [1, 0.5, 0.25].

Copies that add up

Flip, slide, multiply, add

Convolution in code

The working

# step 1/10 · echo

δ[n] = 1 at n = 0, else 0

impulse in  ->  impulse response out
h[0] = 1
h[1] = 0.5
h[2] = 0.25
h[n] = 0 for every other n

more in "The impulse response of a
digital system" (it uses a different
example, h = [0.5, 0.3, 0.2])

The echo h = [1, 0.5, 0.25] and the input x = [1, 2, 3] are chosen example values. Every number and stem in the figure is computed from the convolution sum in this lesson's model; the tests check it against a plain double loop and against numpy's printed output. Convolution does not care about order: x ∗ h = h ∗ x. You may flip and slide x under h instead of h under x, and get the same y.