Convolution of Functions and Sequences
Convolution: A Comprehensive Study Guide
Introduction to Convolution
Convolution is a fundamental way to combine two sequences or functions to produce a new sequence or function. Unlike simple addition or multiplication, which are inherited from operations on numbers, convolution is a genuinely new operation that emerges specifically for lists of numbers or functions.
Convolution appears across many fields:
Probability theory: combining probability distributions
Image processing: blurring, edge detection, sharpening
Differential equations: solving certain classes of equations
Polynomial multiplication: the process of expanding and collecting like terms
Signal processing: moving averages, filtering
The formulaic definition of convolution can appear intimidating, but a visual understanding makes it intuitive and beautiful.
Convolution in Probability: The Dice Example
Simple Uniform Dice
Consider rolling two standard six-sided dice. Each die has six equally likely outcomes. There are 36 possible ordered pairs. The probability of each sum (2 through 12) can be found by counting pairs that yield that sum. When arranged in a grid, pairs with constant sum lie along diagonals. Counting along each diagonal gives the probability distribution.
A different visualization: line up the outcomes of one die in a row. For the other die, flip its row around. Now pairs that sum to 7 line up vertically. Sliding the flipped row by different offsets reveals pairs that sum to other values. For example, offset 0 aligns the pair (1,1) — sum 2; offset 1 aligns (1,2) and (2,1) — sum 3; and so on.
Non-Uniform Dice
If dice are weighted (each face has its own probability), the probability of a particular sum is found by summing the products of probabilities for each pair that gives that sum. For sum 2: P(2)=Pblue(1)×Pred(1). For sum 3: P(3)=Pblue(1)Pred(2)+Pblue(2)Pred(1). In general, the probability of sum n involves all pairs (i,j) where i+j=n.
Let the probability distribution of the first die be a1,a2,…,a6 and the second die be b1,b2,…,b6. Then the convolution of these two sequences gives a new sequence representing the probability distribution of the sum. The process is: flip the second sequence, slide it across the first, and at each offset multiply aligned entries and sum. This is the fundamental operation of discrete convolution.
Notation
The convolution of sequences a and b is denoted a∗b. The nth element of the result is:
The sum runs over all pairs of indices (i,j) such that i+j=n. Equivalently, one can visualize a table of all pairwise products, then sum along diagonals (constant i+j).
Definition: The convolution of two sequences produces a new sequence where each term is a sum of products of terms whose indices sum to a constant.
Simple Example: Convolution of [1,2,3] and [4,5,6]
Let a=[1,2,3] and b=[4,5,6]. The convolution is computed step by step:
Flip b to get [6,5,4] (but in the sliding window method we flip conceptually before alignment).
Align the flipped b so that its first element lines up with the first element of a.
Offset 0: only pair (1,4) → product 1×4=4
Slide b one unit to the right:
Offset 1: pairs (1,5) and (2,4) → 1×5+2×4=13
Slide again:
Offset 2: pairs (1,6), (2,5), (3,4) → 1×6+2×5+3×4=28
Slide again:
Offset 3: pairs (2,6), (3,5) → 2×6+3×5=27
Slide again:
Offset 4: pair (3,6) → 3×6=18
Thus the convolution is [4,13,28,27,18]. This matches the output of standard numerical libraries.
The resulting sequence has length M+N−1, where M and N are the lengths of the original sequences. Here 3+3−1=5.
Moving Average Interpretation
When one of the sequences consists of weights that sum to 1, convolution produces a moving average of the other sequence.
Example: a small list of 5 values, each equal to 51 (so they sum to 1). Sliding this across a longer data sequence, at each position we multiply each data point by 51 and sum — i.e., take the average of the 5 values in the window.
The result is a smoothed version of the original data.
By choosing a different weighting kernel (e.g., giving more weight to the center), we get different smoothing effects — for example, a Gaussian-like kernel produces a smoother, more natural blur.
The condition for a moving average interpretation: the kernel entries must sum to 1. Then each output value is a weighted average of the input values in the window.
Convolution in Image Processing
Blurring
A two-dimensional analog of the moving average: a small grid (kernel) slides across the image. At each pixel position, the kernel values are multiplied by the corresponding pixel values (considering each color channel separately — red, green, blue), and the products are summed. The result becomes the new pixel value for the output image.
Box blur: a 3×3 kernel where each entry is 91. This averages each pixel with its eight neighbors, producing a blur.
Gaussian blur: a kernel sampled from a bell curve (Gaussian distribution). The center value is largest, values decrease toward the edges. This gives more weight to the central pixel, producing a more natural blur (simulating out-of-focus lens).
Note: The pure mathematical definition of convolution requires flipping the kernel 180 degrees before sliding. For symmetric kernels (like box or Gaussian), flipping has no effect, but for asymmetric kernels the order matters.
Edge Detection
Using a kernel that sums to zero (rather than one) can detect edges. Example: a 3×3 kernel with positive values on the left and negative values on the right.
Where the image is uniform (constant color), the sum of products is zero.
Where there is a vertical transition (left side light, right side dark or vice versa), the result is positive or negative.
The output can be displayed using a color code: positive values in blue, negative in red.
This kernel detects vertical edges. Rotating it 90 degrees detects horizontal edges.
Such kernels are often called edge detection filters (e.g., Sobel, Prewitt). The kernel itself is sometimes referred to as a filter kernel or convolution kernel.
General Principle
By choosing different kernels, one can achieve various image processing effects:
Blurring
Sharpening
Edge detection
Embossing
In convolutional neural networks, the kernel values are learned from data, allowing the network to detect features relevant to the task.
Output Size and Truncation
The pure mathematical convolution of an M×N image with a K×L kernel produces an output of size (M+K−1)×(N+L−1). In practice, it is common to truncate or pad the output so that it has the same size as the original image (full convolution vs. same convolution vs. valid convolution). This is an implementation choice.
The Flipping Issue
In computer science contexts, the flipping of the kernel before sliding may feel unnatural. However, it is inherited from the mathematical definition (as seen in the probability and polynomial examples). When the kernel is symmetric, flipping is irrelevant. For asymmetric kernels, one must remember to flip.
Convolution and Polynomial Multiplication
A key insight: multiplying two polynomials is exactly the same process as convolving their coefficient lists.
Example: Multiply (1+2x+3x2) by (4+5x+6x2).
Set up a table of pairwise products:
1×4=4
1×5x=5x
1×6x2=6x2
2x×4=8x
2x×5x=10x2
2x×6x2=12x3
3x2×4=12x2
3x2×5x=15x3
3x2×6x2=18x4
Collect like terms (diagonals where the sum of exponents is constant):
Constant term: coefficient 4
x term: 5+8=13
x2 term: 6+10+12=28
x3 term: 12+15=27
x4 term: 18
The coefficients are [4,13,28,27,18], exactly the same as the convolution of [1,2,3] and [4,5,6].
Thus:
This connection is powerful because it allows using fast algorithms for convolution (via multiplication) and vice versa.
The Fast Convolution Algorithm via FFT
Motivation: Complexity
For two lists of size n, direct convolution requires O(n2) operations: filling an n×n table of pairwise products and summing along diagonals. For large n (e.g., n=100,000), this becomes slow. Using Python's numpy.convolve on two arrays of 100,000 elements takes about 4.87 seconds. However, scipy.signal.fftconvolve (which uses the Fast Fourier Transform) takes only about 4.3 milliseconds — a factor of 1000 improvement.
The Idea: Multiplication of Polynomials via Sampling
If we could turn convolution into pointwise multiplication, we would need only O(n) operations. But convolution corresponds to coefficient multiplication, not pointwise. However, we can:
Interpret the two lists as coefficients of polynomials p(x) and q(x).
Evaluate p and q at a set of sample points.
Multiply the sample values pointwise: r(xk)=p(xk)⋅q(xk).
From these samples, recover the coefficients of r, which are the convolution.
If we choose sample points smartly, steps 2 and 4 can be done in O(nlogn) instead of O(n2).
The Trick: Roots of Unity
Instead of sampling at arbitrary points like 0,1,2,…, sample at the roots of unity — complex numbers evenly spaced on the unit circle. For example, the nth roots of unity are e2πik/n for k=0,1,…,n−1.
Using roots of unity introduces redundancy because powers cycle. This redundancy can be exploited to accelerate both evaluation and interpolation.
The set of values p(ωk) for k=0,…,n−1 is called the discrete Fourier transform (DFT) of the coefficient list.
The Fast Fourier Transform (FFT) algorithm computes the DFT in O(nlogn) time instead of O(n2).
The inverse FFT (IFFT) similarly recovers coefficients from DFT values in O(nlogn).
Algorithm Outline
Given two sequences a and b of length n (pad to a power of 2 for efficiency):
Compute the FFT of a and the FFT of b.
Multiply the two resulting arrays pointwise: ck=FFT(a)k×FFT(b)k.
Compute the inverse FFT of c to obtain the convolution a∗b.
The overall complexity is O(nlogn), a dramatic improvement over O(n2) for large n.
Why This Works
The convolution theorem states:
where F denotes the Fourier transform (discrete or continuous). Convolution in the time/ spatial domain corresponds to pointwise multiplication in the frequency domain. The FFT provides an efficient way to switch between domains.
Key takeaway: The connection between convolution and polynomial multiplication, combined with the FFT, yields a fast algorithm for convolution that is used in probability, image processing, signal processing, and more.
Further Exploration: Homework
Multiplying two integers using the standard digit-by-digit method is essentially a convolution of their digit lists, plus carries. The existence of an O(nlogn) convolution algorithm implies that integer multiplication can also be done faster than O(n2) — in O(nlogn). In practice, numbers need to be extremely large (thousands of digits) for this to outperform conventional algorithms, but it is a theoretically beautiful result.
The fast integer multiplication algorithm (e.g., Schönhage–Strassen, Fürer) relies on this very idea.
Summary of Key Concepts
Discrete convolution is the operation of flipping one sequence, sliding it across another, taking pairwise products and summing at each offset.
It appears naturally in probability (sum distributions), moving averages, image processing (blurring, edge detection), polynomial multiplication, and many other areas.
In image processing, the kernel is flipped (by definition), and the output is often truncated for practical use.
Convolution of coefficient lists is equivalent to polynomial multiplication.
The FFT allows convolution to be performed in O(nlogn) by converting convolution into pointwise multiplication in the frequency domain.
This algorithm is a prime example of how cross-domain connections in mathematics lead to powerful computational techniques.

Ask anything
We've read this whole study set, so questions about it get the best answers.