The system and its input
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].
Now feed it a longer input: x = [1, 2, 3] at n = 0, 1, 2. Everywhere else x is 0. What comes out? Convolution answers that, one sample at a time.
Copies that add up
The system is linear and time-invariant. So x[0] = 1 makes 1·h[n], x[1] = 2 makes 2·h[n − 1], one step later, and x[2] = 3 makes 3·h[n − 2]: three scaled, shifted echoes.
Linear also means the copies add. Stack them at every n and you get y = [1, 2.5, 4.25, 2, 0.75]. That sum is the convolution y[n] = Σ x[k]·h[n − k], written y = x ∗ h.
Flip, slide, multiply, add
Now compute one output at a time. Flip h to get h[−k]: the weights now read 0.25, 0.5, 1, with 1, the weight for the newest input, on the right. Slide it under x. Where it sits is the output time n.
At n = 0 only x[0] = 1 meets a weight, h[0] = 1. The other weights sit over zeros. Multiply each lined-up pair and add: y[0] = 1·1 = 1.
Slide the window one step right, to n = 1. Now two pairs line up: y[1] = 1·0.5 + 2·1 = 2.5. It is the same sum as before, read one output at a time.
At n = 2 the window covers all of x: y[2] = 1·0.25 + 2·0.5 + 3·1 = 4.25. It is the largest output, because every input sample sits under a weight.
Keep sliding. y[3] = 2·0.25 + 3·0.5 = 2, then y[4] = 3·0.25 = 0.75. After that no pairs meet, so y is 0. The output is 3 + 3 − 1 = 5 samples long.
Convolution in code
In Python 3 with numpy, np.convolve(x, h) does every multiply and add for you. It prints the same five numbers: 1, 2.5, 4.25, 2 and 0.75. Its default "full" mode returns N + M − 1 values.
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.