A finite impulse response filter, an image kernel and a CNN layer all form local weighted sums. Their indexing conventions—and the ways we compute them—matter.
The sliding sum
Linear convolution combines input x and kernel h as y[n] = Σₖ x[n−k]h[k]. The n−k reverses the kernel relative to the input before it slides. Boundary choices determine whether the output is full, same-sized or valid-only; they are part of the operation, not presentation detail.
Interactive experiment
One output, multiply by multiply
Which input values contribute to one sample of a three-tap smoothing filter?
The fixed kernel is [0.25, 0.5, 0.25]. Mathematical convolution reverses its indexing; this symmetric kernel looks unchanged, a convenience that can hide the distinction from cross-correlation.
Convolution versus cross-correlation
Cross-correlation uses x[n+k]h[k] and does not reverse the kernel. Most deep-learning APIs implement cross-correlation while naming the layer “convolution”. For learned weights this naming rarely harms optimisation—the network can learn the reversed pattern—but it matters when porting a known filter or comparing values across libraries.
From FIR to feature map
An FIR filter applies one kernel along time. A two-dimensional image filter applies weights across a spatial neighbourhood. A CNN layer adds input and output channels: each output location reduces a small spatial patch across every input channel, then usually adds a bias. Stride samples this output lattice; padding decides what the operator assumes beyond the boundary.
The frequency-domain identity
The DFT of a circular convolution is the pointwise product of DFTs. Linear convolution can use that identity after zero-padding enough to prevent wrap-around. Direct work scales roughly with output length times kernel length; FFT-based work adds transforms and pointwise products. Which is faster depends on sizes, batching, cache behaviour, implementation and hardware. No universal crossover is claimed here.
Where the analogy breaks
A classical filter is normally designed for a specified frequency response and remains fixed. A CNN kernel is fitted jointly with nonlinear layers, channel mixing and a loss. Inspecting its spectrum can be informative, but it does not reduce the network to an ordinary linear time-invariant system.
Implementation checklist
- Write down reversal, padding, stride and dilation conventions.
- Test impulse and boundary cases.
- Zero-pad before using an FFT for linear convolution.
- Measure the intended shape and hardware before selecting an algorithm.