Convolution Calculator: Tutorial Design convolution calculator Matlab
Complete StepbyStep Tutorial Design Convolution Calculator Matlab
For upon Hello friends, hope you all are fine and having fun with your lives. In today’s post, I am gonna design a Convolution Calculator in MATLAB. We all know about convolution but if you don’t know then here’s the wiki page for convolution which has a detailed description of Convolution. In simple words, convolution is a mathematical operation, that applies to two values say f and g, and gives the third value as an output say v. In convolution, we do pointtopoint multiplication of input functions and get our output function.
important technique
Convolution is an important technique and is used in many stimulating projects. It has a vital importance in image processing. So, today we are gonna do convolution in MATLAB and will check the output. You should also check Image Zooming with Bilinear Interpolation in MATLAB in which we have used a correlation technique that is quite similar to convolution. It will give you a better idea of convolution, I recommend you to read their difference. Anyways, coming back to today’s Convolution Calculator, let’s start its designing:
Convolution Calculator in MATLAB
 MATLAB has a builtin command for convolution using which we can easily find the convolution of two functions.
 The syntax of this builtin convolution command is v=conv(x,h) where x and h are the input functions while v is our output.
 In my code, I have used this builtin function as well and I have also designed a small algorithm for calculating the convolution using its formula.
 After finding both the convolutions, I have simply compared them by plotting them on a graph so that we can also verify that our result is correct.
 You can use this convolution calculator to find the convolution of any two functions.

So, first of all, copy this code paste it into your m file, and run it in your MATLAB:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

CLC
close all
clear all
x=input(‘enter the sequence, x(n)=’)
h=input(‘enter the sequence, h(n)=’)
m=length(x);
n=length(h);
subplot(4,1,1)
stem(1:m,x,‘fill’,‘R’)
grid on;
title(‘input sequence, x(n)=’)
Xlabel(‘time n——>’)
Ylabel(‘amplitude—–>’)
subplot(4,1,2)
stem(1:n,h,‘fill’,‘r’)
grid on;
title(‘impulse sequence, h(n)=’)
Xlabel(‘time n——>’)
Ylabel(‘amplitude—–>’)
%———linear convolution using inbuilt command————————————%
v=conv(x,h)
l=m+n–1;
subplot(4,1,3)
stem(1:l,v,‘fill’,‘R’)
grid on;
title(‘output sequence using inbuilt command, v(n)=’)
Xlabel(‘time n——>’)
Ylabel(‘amplitude—–>’)
%————linear convolution using ‘for’ loop———————————————%
X=zeros(1,l);
H=zeros(1,l);
X(1:m)=x;
H(1:n)=h;
for i=1:l
Y(i)=0;
for j=1:i
Y(i)=Y(i)+X(j)*H(i–j+1);
end
end
Y
subplot(4,1,4)
stem(1:l,Y,‘fill’,‘R’)
grid on;
title(‘output sequence using loop, Y(n)=’)
Xlabel(‘time n——>’)
Ylabel(‘amplitude—–>’)

 The above code for convolution calculator is quite selfexplanatory but let me explain it a little.
 First of all, I am asking for inputs from the user and they are saved in variables named x and h.
 After that, I plotted them using the stem function.
 In the next section, I used the default MATLAB command for Convolution calculated the convolution of x and h, and saved it in v.
 Next, I applied my simple algorithm and calculated the convolution of x and h saved it in Y, and also plotted it.
 Once you run the simulation and give your input functions, you will get the below results:
 MATLAB
 You can see in the above figure that I have given two inputs x and h and MATLAB Convolution Calculator calculated the convolution and gave us v and Y.
 v is calculated by default MATLAB command while the Y is calculated by our small convolution algorithm.
 Their graph representation is shown in the below figure:
 You can see in the above figure that we have plotted all four signals, two inputs and two outputs and you can see both the outputs are same.
 Here’s the video for this convolution calculator in MATLAB:
That’s how you can design a convolution calculator in MATLAB. Let me know about your experience with this convolution calculator. I am planning to design a GUI for this calculator and will add it in this post.
Comments are closed.