REGNO:311119106029 Melodina Carnelian D Loyola - Icam College of Engineering and Technology (Licet)
REGNO:311119106029 Melodina Carnelian D Loyola - Icam College of Engineering and Technology (Licet)
MELODINA CARNELIAN D
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
Ex.No -2
Linear and Circular Convolution
Date:04-09-21
AIM:
To write a MATLAB program to obtain the linear and circular convolution of two sequences.
APPARATUS REQUIRED:
MATLAB, PC
THEORY:
For a linear time invariant system if the input sequence x(n) and impulse response h(n) is
given ,we can find the output y(n) by using the equation(n)=∑x(k) h(n-k),where k varies from -∞
to +∞ which is known as convolution sum and can be represented as y(n)=x(n)*h(n),where *
denotes the convolution operation. This is an extremely powerful result that allows us to compute
the system output for any input excitation.
ALGORITHM:
1. Choose an initial value of n, the starting time for evaluating the output sequences y(n).If
x(n) starts at n=n1 and hence h(n) starts at n=n2 then n=n1+n2 is good choice
2. E expresses both sequences in terms of the index k
3. Fold h (K) about k=0 to obtain h (-K) and shift by n to the right if h is positive and left if n is
negative to obtain h (n-k).
4. Multiply the two sequences x (k) and h (n-k) element by element and the sum of products to
get y (n).
5. Increment the index n, shift the sequence h (n-k) to right by one sample and do step 4.
6. Repeat step 5 will until the sum of products is zero for all remaining values of n.
PROGRAM:
1. LINEAR CONVOLUTION FUNCTION
y=conv(x,h);
subplot(3,1,1);
stem(x);
1
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
ylabel('Amplitude->');
xlabel('N->');
subplot(3,1,2);
stem(h);
ylabel('Amplitude->');
xlabel('N->');
subplot(3,1,3);
stem(y);
ylabel('Amplitude->');
xlabel('N->');
title('linear Convolution');
INPUT:
OUTPUT:
2
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
x=sin(2*pi*0.1.*(1:1:11));
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
figure;
INPUT:
3
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
OUTPUT:
N=length(x1)+ length(x2)-1;
X1=fft(x1,N);
X2=fft(x2,N);
Y=X1.*X2;
y=ifft(Y);
disp(y);
stem(y)
INPUT:
Enter the sequence x1(n)=
[8 7 6 5]
Enter the sequence x2(n)=
[5 9 4 2]
4
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
OUTPUT:
4. CIRCULAR CONVOLUTION
clc;
close all;
x1=input('Enter the first sequence :');
x2=input('Enter the second sequence: ');
N1=length(x1);
N2=length(x2);
N=max(N1,N2);
if(N2>N1)
x4=[x1,zeros(1,N-N1)];
x5=x2;
elseif(N2==N1)
x4=x1;
x5=x2;
else
x4=x1;
x5=[x2,zeros(1,N-N2)];
end
x3=zeros(1,N);
for m=0:N-1
x3(m+1)=0;
for n=0:N-1
j=mod(m-n,N);
x3(m+1)=x3(m+1)+x4(n+1).*x5(j+1);
end
5
end
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
subplot(4,1,1)
stem(x1);
title('First Input Sequence');
xlabel('Samples');
label('Amplitude');
subplot(4,1,2)
stem(x2);
title('Second Input Sequence');
xlabel('Samples');
ylabel('Amplitude');
subplot(4,1,3)
stem(x3);
title('Circular Convolution Using Modulo Operator');
xlabel('Samples');
ylabel('Amplitude');
INPUT:
Enter the first sequence :
[7 6 5 4 3]
Enter the second sequence:
[8 3 4 5 2]
OUTPUT:
RESULT:
Thus a MATLAB program is written to obtain the linear and Circular convolution of two
sequences.
6