Signals to learning / 5. Build systems

Lesson 18 of 40 · Intermediate · About 30 minutes

Convolution step by step

Which input samples contribute to one output?

You will be able to

  • Calculate a convolution sum with zero extension.
  • Distinguish convolution from cross-correlation.

Shift, multiply, add

For y[n]=Σₖh[k]x[n−k], each output adds weighted earlier input values. As n changes, the contributing input indices move. Outside a finite record we use zero extension here. Full convolution has N+M−1 samples for nonempty arrays of lengths N and M.

Kernel direction matters

Cross-correlation often uses x[n+k] rather than x[n−k], without reversing the kernel under the same sliding-array presentation. Deep-learning libraries commonly call this operation convolution. Symmetric kernels can conceal the difference; use an asymmetric one to check the convention. Padding changes boundary values and output shape.

y[n]=Σₖh[k]x[n−k]; full length=N+M−1

Worked example

For x=[1,2] and h=[1,3], full convolution is [1,5,6]: y[1]=1×2+3×1=5. The asymmetric h makes reversal conventions visible.

A common trap

A padding rule is part of the operation; “same” output size does not tell you the actual boundary values or alignment.

Predict, then experiment

At output index 0, can negative-index input values contribute under zero extension? Before touching the controls, say or write your prediction.

Interactive experiment

One output, multiply by multiply

Which input values contribute to one sample of a three-tap smoothing filter?

Blue is the input and dashed amber is the full output. The moving window and filled blue points show the samples under the kernel; the large amber point is the selected output. The fixed kernel is [0.25, 0.5, 0.25].

Your experiment

Move the index from 0 to 9. Inspect the highlighted input indices and exact product sum. Compare the first, interior and last outputs.

Change one parameter at a time. Compare what you observed with your prediction and record an explanation in your notes.

Check your understanding

Try from memory first. Hints and feedback are part of learning, not a penalty. These checks are for self-study, not a graded qualification.

1. Which kernel best reveals convolution versus correlation differences?
Give me a hint

What changes when a sequence is reversed?

2. What is the full convolution length for input length 8 and kernel length 3?

Accepted absolute tolerance: ±0.001 samples.

Give me a hint

Include both boundary tails.

Reference answers (after your attempt)
  1. An asymmetric kernel — Correct: reversal changes its ordering.
  2. 10samples — 8+3−1=10.

Apply it: Implement the definition

Use paper, your notes, or a local notebook/editor. Code examples are Python 3 starting points to run yourself; this page does not execute code or automatically assess the practical task.

  1. Compute [1,2]*[1,3] by hand.
  2. Write a zero-extended loop or use the reference.
  3. Compare the result with an asymmetric cross-correlation.
Reference code / starting point
x, h = [1, 2], [1, 3]
y = [sum(h[k] * x[n-k] for k in range(len(h))
         if 0 <= n-k < len(x))
     for n in range(len(x)+len(h)-1)]
print(y)
Reference solution & review criteria

Full convolution is [1,5,6]. A valid cross-correlation for these equal-length arrays gives [1×1+2×3]=[7], which is a different operation and output convention.

Your notebook

Notes and progress stay in this browser. They are not sent to the server; ordinary web-server request logs still operate. Export a backup from the course page.

Review list

Completion requires both correct checks and your practical-task acknowledgement.

Go deeper

Sources support further study; the worked examples and questions here are original. Browser experiments are small, disclosed models—not evidence of production-model quality or hardware performance.