Linear Convolution using C and MATLAB

A key concept often introduced to those pursuing electronics engineering is Linear Convolution. This is a crucial component of Digital Signal Processing and Signals and Systems. Keeping general interest and academic implications in mind, this article introduces the concept and its applications and implements it using C and MATLAB.

Convolution: When speaking purely mathematically, convolution is the process by which one may compute the overlap of two graphs. In fact, convolution is also interpreted as the area shared by the two graphs over time. Metaphorically, it is a blend between the two functions as one passes over the other. So, given two functions F(n) and G(n), the convolution of the two is expressed and given by the following mathematical expression:

f(t)*g(t)=\int_{-\infty }^{\infty} f(u).g(t-u)du

or

f(n)*g(n)=\sum_{k=-\infty}^{\infty} f(k).g(n-k)

Linear convolution

So, clearly intuitive as it looks, we must account for TIME. Convolution involves functions that blend over time. This is introduced in the expression using the time shift i.e., g(t-u) is g(t) shifted to the right ‘u’ times). Additionally, how we characterize this time is also important. Before proceeding further, let us compile the prerequisites involved:

Linear Convolution: Linear Convolution is a means by which one may relate the output and input of an LTI system given the system’s impulse response. Clearly, it is required to convolve the input signal with the impulse response of the system. Using the expression earlier, the following equation can be formed-

f(n)*h(n) = \sum_{k=-\infty}^{\infty}f(k).h(n - k)

The reason why the expression is summed an infinite number of times is just to ensure that the probability of the two functions overlapping is 1. The impulse response is time-shifted endlessly so that during some duration of time, the two functions will certainly overlap. It may seem it would be careless on behalf of the programmer to run an infinite loop – the code may continue to execute for as long as the two functions do not overlap.

The solution lies in the fact LTI systems are being used. Since the functions do not change their values/shape over time (time-invariant), they can simply be slid closer to each other. Remember only the output is required, and it is not important ‘when’ the output is received. All manual calculations also depend on the same idea.

Explanation: Here’s one technique that may be used while calculating the output:

<a href=Explanation of Linear Convolution" />

Approach:

Below is the Matlab program to implement the above approach: