Calculating the Convolution of Two Functions With Python

Rhett Allain
The Startup
Published in
7 min readAug 10, 2020

--

Photo: Rhett Allain

What is a convolution? OK, that’s not such a simple question. Instead, I am will give you a very basic example and then I will show you how to do this in Python with actual functions.

So, suppose you have an object and a camera. The object is the Sun — which produces different frequencies of light at different intensities. You could consider this frequency distribution of intensities a function (I’m going to call this function f). Next, you have a camera. The camera isn’t perfect. It is more sensitive to different frequencies of light. I’ll call this camera frequency sensitivity the function g.

When you capture an image of the Sun with this camera, you get some data. That data shows the intensity of different frequencies of light — but this data depends on both the Sun (function f) AND the camera (function g). The data you get would be the convolution of f and g.

OK, I’m not sure if that’s the best example of a convolution — but I’m going to move forward anyway. Actually, I’ve seen this awesome animation of a convolution and I think it helps explain the thing. I’ll go through the steps to make this down below.

--

--

Rhett Allain
The Startup

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.