EXPERIMENT 4
Aim : To calculate linear and circular convolution of discrete time signals
Software: - MATLAB 2020b
Group Member:
1. Omkar Bhilare 191060901
2. Omkar Sargar 181060047
3. Om Fuke 181060046
4. Lukesh Ankamwar 181060038
Matlab Code:
t = -5:1:5;
start_time1 = input("Enter the start time: ");
signal1 =input('Enter the sequence 1:', 's');
signal1 = eval(signal1);
t1 = start_time1:1:start_time1+length(signal1)-1;
start_time2 = input("Enter the start time: ");
signal2 =input('Enter the sequence 2:', 's');
signal2 = eval(signal2);
t2 = start_time2:1:start_time2+length(signal2)-1;
start = start_time1+start_time2;
lent = length(t1)+ length(t2) - 1;
flag = input("Enter 1 for linear convolution and 2 for
circular");
if flag ==1
y_linear=conv(signal1,signal2);
t3 = start:1: start+lent-1;
subplot(3,1,1);
stem(t1,signal1);
ylabel('Signal X');
xlabel('Time [n]');
title('Input sequence X')
subplot(3,1,2);
stem(t2,signal2);
ylabel('Signal h');
xlabel('Time [n]');
title('Input sequence h')
subplot(3,1,3);
stem(t3,y_linear);
ylabel('Y = X*h');
xlabel('Time [n]');
title('Linear Convolution');
else
y_circular = cconv(signal1, signal2, length(signal1));
t4 = start: 1: start+ length(signal1) -1;
subplot(3,1,3);
stem(t4, y_circular);
ylabel('Y');
xlabel('Time [n]');
title('Circular Convolution');
end
function out = unit_step(t)
x1 = 1;
x0 = 0;
out = x1.*(t>=0) + x0.*(t<0);
end
function out = ramp(t)
x1=t;
x0=0;
out = x1.*(t>=0) + x0.*(t<0);
end
Code Output:
Theoretical Analysis: -
1. Linear Convolution:
Example: x [n] = [1,2,3 4] h [n]
= [4,3,2,1];
By Tabular method,
T1 = 4, T2 = 4 and hence T = Ti + T2 -1 = 7. So there should be 7
diagonals in the table. N1 = 2 and N2 = 3, so N = N1+ N2 = 5. So there
should be five elements to the left of y [0].
x[-2] = 1 x[-1] = 2 x[0] = 3 x[1] = 4
h[-3] = 4 4 8 12 16
h[-2] = 3 3 6 9 12
h[-1] = 2 2 4 6 8
h[0] = 1 1 2 3 4
Now adding all the
d
y[-5]=4 * 1 =4
y[-4]=3 * 1 +4 * 2 =11
y[-3]=2 * 1+3 * 2 +4 * 3 =20
y[-2] = 1 * 1 +2 * 2+ 3 * 3+ 4 * 4 = 30
y[-1] = 1 * 2+ 2 * 3+ 3 * 4 = 20
y[0] = 1 * 3 + 2 * 4 = 11
y[1] = 1 * 4 =4
y [n] = [4,11,20,18,20,11,4]
Circular Convolution
Example:
x [n] = [1,2,3,4]
h [n] = [5, 2, 1]
h [n] = [5, 2, 1, 0]
By Matrix method
1 4 3 2
2 1 4 3
3 2 1 4
4 3 2 1
5
Multiplying both the matrices , we get
16
16
20
28
Conclusion: -
In this practical we calculated the linear and circular convolution of two different discrete
time signals using two different theoretical approaches respectively and also with the
software. Through the results we can prominently see the differences between the two
convolutions.