Convolution of Functions and Sequences


Convolution of Functions and Sequences

Simon
So Hope, have you ever thought about ways to combine two lists of numbers or functions? You can add them term by term, multiply them, but there's this other operation called convolution that's just as fundamental.

Hope
Convolution? I've heard the term in signal processing and image editing, but I'm not entirely sure what it means. Is it really that different from just adding or multiplying?

Simon
Absolutely. Unlike addition or multiplication, convolution isn't just inherited from an operation on numbers. It's something new. And it shows up everywhere: probability, differential equations, image processing, even multiplying polynomials.

Hope
I've definitely multiplied polynomials before. Where's the connection? Let's start with the probability example you mentioned.

Simon
Think about rolling two dice. To find the probability of getting a sum of 7, we count all pairs that add to 7. With uniform dice, that's simple counting. But what if the dice have different probability distributions?

Hope
Right, if each face has its own probability, then the chance of a sum is the sum of products of probabilities from each die. That's starting to sound like a convolution.

Simon
Exactly! For two lists a and b, the convolution at index n is the sum over all i and j where i+j equals n of a_i times b_j. It's like flipping one list and sliding it across the other, multiplying and adding.

Hope
So that sliding window view is key. And you mentioned a moving average? That's another example, right?

Simon
Yes! If you have a list of data and a small kernel that sums to 1, convolve them and you get a smoothed version. Each output is a weighted average of nearby data points. The same idea works for images: a blurring effect.

Hope
I've seen image blurring. How does that work? You take a small grid of numbers, like a 3x3 kernel with all 1/9, and slide it over the image?

Simon
Exactly. For each pixel, you multiply the kernel values by the underlying pixel colors and sum them. That gives the new pixel. It's a convolution between the image and the kernel. If the kernel is symmetric, you don't notice the flip, but mathematically you always flip the kernel.

Hope
What if the kernel has negative numbers? I've heard of edge detection.

Simon
Yes! A kernel like a Sobel operator detects vertical edges: one side positive, the other negative. When you slide it over a uniform area, the sum is zero, but at an edge, you get a large positive or negative value. That highlights the edge.

Hope
So convolution is incredibly useful. But you also mentioned a connection to polynomial multiplication?

Simon
Right! If you represent polynomials by their coefficients, multiplying them is exactly a convolution. For example, (1 + 2x + 3x²) times (4 + 5x + 6x²) gives a product where each coefficient is a sum along diagonals of a multiplication table.

Hope
That's neat. But what's the big deal? Polynomial multiplication is straightforward.

Simon
The big deal is that this connection leads to a much faster algorithm. Usually, convolving two lists of size n takes O(n²) operations. But if we treat them as polynomial coefficients and use a trick, we can do it in O(n log n).

Hope
How? That sounds impossible.

Simon
The trick is the Fast Fourier Transform, or FFT. Instead of computing the convolution directly, you compute the discrete Fourier transform of each list, multiply those pointwise, then inverse transform. And the FFT is super efficient because it evaluates polynomials at special points—roots of unity—exploiting symmetry.

Hope
So that's why Python's scipy.signal.fftconvolve is so much faster than numpy.convolve for large arrays.

Simon
Exactly! For arrays of 100,000 elements, the direct method might take seconds, but FFT-based convolution takes milliseconds. And it's used in everything from audio processing to probability distributions.

Hope
You also mentioned that normal distributions naturally appear in convolutions. That sounds fascinating.

Simon
We'll save that for part two of our conversation. But to wrap up, convolution is a beautiful operation that combines sequences in a way that's both intuitive and powerful. And thanks to the FFT, it's also computationally efficient.

Hope
I'm starting to see why it's everywhere. Thanks, Simon! I'll definitely think about convolution the next time I blur an image or roll some dice.

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