Machine Learning & AI
Advanced

Discrete Convolution

Slides a filter over an input to detect local patterns; the core of CNNs.

Formula

(f∗g)(t)=∑τf(τ) g(t−τ)(f*g)(t)=\sum_{\tau} f(\tau)\,g(t-\tau)

Variables

fInput signal
gKernel/filter
\tauShift index

Example

A 3x3 edge kernel highlights boundaries

How it works

Discrete convolution combines two sequences by reversing one of them, shifting it across the other, multiplying overlapping values, and summing the results at each position. This works because each output value measures how strongly the local neighborhood of the input matches the pattern encoded by the kernel, which is why convolution is so useful for feature detection. In machine learning, it lets a CNN reuse the same small set of weights across many locations, making pattern recognition efficient and translation-aware.

When to use it

Use discrete convolution when you need to extract local features from sampled data such as images, audio waveforms, or time-series signals. It is especially useful in CNNs, signal processing, smoothing, edge detection, and any setting where the same pattern may appear in different positions.

Worked example, step by step

Let f = [2, 1, 0] and g = [1, -1]. Using (f*g)(t)=\sum_{\tau} f(\tau)g(t-\tau), compute each output value: For t = 0: (f*g)(0) = f(0)g(0) = 2·1 = 2 For t = 1: (f*g)(1) = f(0)g(1) + f(1)g(0) = 2·(-1) + 1·1 = -2 + 1 = -1 For t = 2: (f*g)(2) = f(1)g(1) + f(2)g(0) = 1·(-1) + 0·1 = -1 + 0 = -1 For t = 3: (f*g)(3) = f(2)g(1) = 0·(-1) = 0 Final result: (f*g) = [2, -1, -1, 0]

Common mistakes to avoid

  • Forgetting that one sequence is shifted relative to the other, which changes the sign/order of the kernel indexing
  • Confusing convolution with cross-correlation and failing to reverse the kernel when required
  • Ignoring boundary handling, which can change the output length and edge values

Did You Know?

Convolutional nets are inspired by the visual cortex, where neurons respond to local regions.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026