0% found this document useful (0 votes)
43 views

REGNO:311119106029 Melodina Carnelian D Loyola - Icam College of Engineering and Technology (Licet)

The document describes a MATLAB program to perform linear and circular convolution of sequences. It includes: 1) An introduction explaining linear convolution and how it can be used to find the output of a linear time-invariant system. 2) An algorithm for implementing linear convolution in MATLAB. 3) Sections of MATLAB code demonstrating linear convolution using the conv function, without a function, and using circular convolution. 4) An input/output example for each section of code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

REGNO:311119106029 Melodina Carnelian D Loyola - Icam College of Engineering and Technology (Licet)

The document describes a MATLAB program to perform linear and circular convolution of sequences. It includes: 1) An introduction explaining linear convolution and how it can be used to find the output of a linear time-invariant system. 2) An algorithm for implementing linear convolution in MATLAB. 3) Sections of MATLAB code demonstrating linear convolution using the conv function, without a function, and using circular convolution. 4) An input/output example for each section of code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

REGNO:311119106029

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

x=input('Enter the sequence x:');

h=input('Enter the sequence y:');

y=conv(x,h);

subplot(3,1,1);

stem(x);

1
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

ylabel('Amplitude->');

xlabel('N->');

title('Input sequence x')

subplot(3,1,2);

stem(h);

ylabel('Amplitude->');

xlabel('N->');

title('Input sequence h')

subplot(3,1,3);

stem(y);

ylabel('Amplitude->');

xlabel('N->');

title('linear Convolution');

INPUT:

Enter the sequence x:


[1 2 3 5 6 7 8]

Enter the sequence y:


[ 7 6 5 4 6 3 2]

OUTPUT:

2
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

2. LINEAR CONVOLUTION WITHOUT FUNCTION

x=input('Enter the sequence x:');

h=input('Enter the sequence y:');

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;

subplot(3,1,1); stem(x, '-b^'); xlabel('n');

ylabel('x[n]'); grid on;

subplot(3,1,2); stem(h, '-ms');

xlabel('n'); ylabel('h[n]'); grid on;

subplot(3,1,3); stem(Y, '-ro');

ylabel('Y[n]'); xlabel('----->n'); grid on;

title('Convolution of Two Signals without conv function');

INPUT:

Enter the sequence x:


[1 2 3 4 5 8 10 12]

Enter the sequence y:


[[1 2 3 4 5 3 1 -1]

3
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

OUTPUT:

3.LINEAR CONVOLUTION USING CIRCULAR CONVOLUTION

x1=input('Enter the sequence x1(n)=');

x2=input('Enter the sequence x2(n)=');

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:

40.0000 107.0000 125.0000 123.0000 83.0000 32.0000 10.0000

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

You might also like