PROGRAM 1:
%Name: Mouleshwar Saravanan
%Roll No.: [Link].U4ELC20040
%Objective: To compute the circular convolution of two
sequences
%Inputs: The elements of the two sequences
%Outputs: The circular convolution of the two
sequences
clear all
clc
close all
x1 = input("Enter the 1st sequence: ");
x2 = input("Enter the 2nd sequence: ");
N1 = length(x1);
N2 = length(x2);
N = max(N1,N2);
disp(" ");
%If lengths of the two sequences are not equal, do
zero padding for either sequence
if N1 < N2
x1 = [x1,zeros(1,N-N1)];
elseif N2 < N1
x2 = [x2,zeros(1,N-N2)];
end
%Computing circular convolution using for loop and mod
function
disp("Circular Convolution: ");
for m = 1:N
x3a(m) = 0;
for n = 1:N
j = mod(m-n,N1);
x3a(m) = x3a(m) + x1(n).*x2(j+1);
end
end
disp(x3a)
%Plotting the graphs
subplot(4,1,1)
stem(x1)
title("1st Sequence")
xlabel("Samples")
ylabel("Amplitude")
subplot(4,1,2)
stem(x2)
title("2nd Sequence")
xlabel("Samples")
ylabel("Amplitude")
subplot(4,1,3)
stem(x3a)
title("Circular Convolution using for loop and mod
function")
xlabel("Samples")
ylabel("Amplitude")
%Computing circular convolution using cconv function
and plotting the graph
x3b = cconv(x1,x2,N)
subplot(4,1,4)
stem(x3b)
title("Circular Convolution using cconv function")
xlabel("Samples")
ylabel("Amplitude")
disp(x3b-x3a)
PROGRAM 2:
%Name: Mouleshwar Saravanan
%Roll No.: [Link].U4ELC20040
%Objective: To compute the linear convolution of two
sequences using circular convolution
%Inputs: The elements of the two sequences
%Outputs: The linear convolution of the two sequences
clear all
clc
close all
x1 = input("Enter the 1st sequence: ");
x2 = input("Enter the 2nd sequence: ");
N1 = length(x1);
N2 = length(x2);
N = N1+N2-1;
%Zero padding to make the lengths of both sequences
equal to N
x1 = [x1,zeros(1,N-N1)];
x2 = [x2,zeros(1,N-N2)];
%Computing linear convolution using for loop and mod
function
disp("Linear Convolution: ");
for m = 1:N
x3a(m) = 0;
for n = 1:N
j = mod(m-n,N);
x3a(m) = x3a(m) + x1(n).*x2(j+1);
end
end
disp(x3a)
%Plotting the Graphs
subplot(4,1,1)
stem(x1)
title("1st Sequence")
xlabel("Samples")
ylabel("Amplitude")
subplot(4,1,2)
stem(x2)
title("2nd Sequence")
xlabel("Samples")
ylabel("Amplitude")
subplot(4,1,3)
stem(x3a)
title("Linear Convolution Using For Loop and Mod
Function")
xlabel("Samples")
ylabel("Amplitude")
%Computing linear convolution using conv function and
plotting the graph
x3b = conv(x1,x2,'full')
subplot(4,1,4)
stem(x3b)
title("Linear Convolution using conv Function")
xlabel("Samples")
ylabel("Amplitude")