Why Convolution Matters - MATLAB & Simulink
Video Player is loading.
Current Time 0:00
Duration 9:58
Loaded: 2.97%
Stream Type LIVE
Remaining Time 9:58
 
1x
  • Chapters
  • descriptions off, selected
  • captions off, selected
      Video length is 9:58

      Why Convolution Matters

      Explore what convolution is and why it matters. Convolution is a mathematical operation between two functions. It is a foundational concept in fields such as signal processing and image processing. The convolution integral looks complex but can be broken into pieces to understand the operations behind it. Convolution describes ordinary phenomena seen every day, such as echoes in a cave. It is behind the techniques that allow smartphones to take pictures and receive phone calls. Learn the concepts behind convolution and why scientists and engineers use its properties to design systems.

      Published: 4 Oct 2024

      Convolution, it's wildly important for signal processing, image processing, statistics, engineering, physics, the list goes on. So it's worth it for us to spend some time deepening our understanding of what it is and when to use it. And that's what we're going to do today. Let's explore why convolution matters.

      [MUSIC PLAYING]

      Convolution is an integral defined by this equation here. Now, this might look scary at first, but let's break it down to get a better understanding. Convolution calculates how the shape of one function f is modified by another g. It slides one function over the other, multiplying and integrating their product at each step, effectively blending them together in some way.

      Think of f of tau as capturing a snapshot of the first function at a specific moment, tau. g of t minus tau flips the second function around and shifts it to align with the moment we're considering. By multiplying these two snapshot values, we're calculating the degree of their interaction, essentially asking, how much does the shape of one function at this moment affect the shape of the other? The integral then tells us to add up all these interactions over every possible tau, giving a complete picture of how the entire first function is transformed by the entirety of the second.

      Still confused? Visually, it looks like this. We start with two functions, f and g. To convolve them, g is flipped in time, and then we sweep it across the entirety of f. For each moment in time, as g is swept across f, we multiply the two functions together and then sum the result.

      Essentially, we're scaling one function by the other-- that's the multiplication-- and then returning the area under the curve. That's the integral. So despite the convoluted looking equation, calculating a convolution is pretty straightforward mathematically, just multiplying and summing two functions across time. And it's even more straightforward with the conv function in MATLAB, which we'll be employing to calculate our convolutions today.

      Here we're using the continuous time convolution integral, but there's also a discrete time equivalent where the integral is replaced with discrete summation. The discrete time version is hugely important in science and engineering because of how prevalent digital signals are in those fields.

      But, fundamentally, the concept is the same in both domains. Now that we have a better understanding of the mathematics behind convolution, it's time to get into why it's so important to so many different applications. What exactly is it doing for us, and which types of problems does it help us solve? Well, let's dive in.

      Let's get into an example where we can see convolution in action. It's one you may have heard of before, sound. Imagine you're standing in a big, empty and quiet room, and you let out a short yell. We'll call that an impulse. Those sound waves created by the impulse will leave your mouth, bounce around the room, and dissipate over time. We'll call that the impulse response.

      So what you hear after you yell is an initial loud sound, which then tapers off as you hear some of the quieter reflections from around the room until the sound is gone completely. The shape and materials of the room define what this response looks like. And by changing the room, we can get different responses. For example, a small room with a lot of carpet and furniture would not reflect much of the sound, whereas a large room with a lot of glass would be very echoey.

      What does this have to do with convolution? Let's say you yell. And before the room's impulse response, g, dies out completely, you yell again. This creates a new impulse input function, f. The total sound in the room will be the combination of the new yell plus whatever is left over from the first yell.

      This means that at any moment in time, tau, we can figure out what the room sounds like by simply convolving the impulse response of the room, g, with the inputs into the room, f. Using the conv function, we take the convolution equation, add in the signals f and g. And the solution produced is the calculation of the total sound in the room.

      We could even calculate what the room will sound like over time with any input, like with continuous talking or with music playing, simply by knowing which sounds are being injected into the room, function f, and the acoustics of the room, function g. It's just a convolution of the two.

      Let's take this specific example of sound and expand on it. A sound wave is just one of endless types of signals all around us. And convolution is vital for processing and filtering these signals. So far, we've just been observing sound waves as they propagate throughout a room. But what if we wanted to intentionally design a response for the sound waves to follow?

      Physically, you'd change this by altering the layout or makeup of the room, which would change the room's impulse response. But let's say you had a signal you wanted to alter mathematically. You do this by creating a filter. And like the room, we can understand the filter by looking at its impulse response, which we then apply to the signal through convolution.

      For example, let's say you have a digital signal from a sensor, like a microphone picking up sound waves, and you want to filter out the high-frequency noise. This can be done with a low-pass filter, and a simple version of that is the moving average. A moving average filter attenuates the higher frequencies by smoothing over abrupt changes or sharp peaks in the signal, while leaving the lower frequencies alone. If we put the initial signal, f, and the impulse response, g, into the conv function, we can determine the filtered result, a moving averaged version of the original signal.

      Now, let's listen to the results. As the filter gets applied to my audio, (MUFFLED) you can hear that the low frequencies remain while the high frequencies are eliminated, resulting in my voice now sounding rather muffled.

      When it comes to filter design, we're often concerned with the frequency characteristics of a signal, which can be hard to visualize and design in the time domain. And up till now, we've only talked about convolution as being a time domain function. Thankfully, there's a nice symmetry between convolution and multiplication for the time and frequency domains.

      Convolving two time domain signals is equivalent to multiplying those signals in the frequency domain. And the opposite is true as well. Convolving two frequency signals is the same as multiplying their time counterparts.

      So just keep this in mind that if you're doing filter design, you may never calculate the convolution integral directly, but the same concept is being applied when you multiply two frequency signals together. As this moving average example shows, we can design any number of interesting and useful filters for processing signals simply by shaping the impulse response.

      All right, we've talked a lot about one-dimensional signals like sound waves, but what if we add another dimension to our signals? It turns out that convolution can also be done on two-dimensional signals. And what is a two-dimensional signal? Well, images are. We just discussed getting the moving average of a sound signal.

      And we can do this same filtering scheme with an image. This is called a blur filter. To apply this to an image of yours truly, we take a kernel, a 2D filter with specific size and values in it, and pass it over the image, multiplying and summing pixel by pixel to create a product which is a modified version of the original image.

      I'm sure we've all seen a blurred image before. And this is precisely what it is, using a kernel with values like these to create a moving average of an image, filtering out the high-frequency details and producing a blur effect.

      In addition to blurring an image, we can also perform edge detection on the image through using a kernel with values like these to highlight areas in the image that have stark changes in color values. Not only can we detect edges, but we can refine them as well with a sharpening filter. Applying a kernel with values like these causes edges to be more defined, thus adding a sharpened look to the image.

      The foundations of image processing are powered by convolution, and the mighty kernel can be used to manipulate or even analyze an image in all sorts of ways. Advances in artificial intelligence have taken image convolution even further. We just learned that with some clever kernel design, we can do things like detect edges and sharpen images. If we use a common deep learning model like a convolutional neural network, machines can take data and learn how to design kernels for different tasks.

      For example, we could load millions of labeled images of various animals into a computer. Then the computer uses an algorithm to iteratively design and optimize hundreds of kernels. These kernels are then used to process images, which allows the computer to tell the difference between a dog and a cat. All this is built on the simple yet powerful operation of convolution.

      Convolution is all around us and ridiculously important. In this video, we've only scratched the surface of all the ways it impacts our lives. In fact, maybe you can think of some other applications that rely on convolution. If you can think of any, leave them in the comments below.

      For more information on convolution in MATLAB, check out The MathWorks Discovery Page for Convolution, as well as interactive on-ramp courses for signal processing and image processing all linked the description. Thanks for watching, and I'll see you in another video.