You are on page 1of 3

EXPERIMENT NO:-5

AIM:- Write a MATLAB program to evaluate the linear convolution between two
sequences.

THEORY:-
Convolution is used in DSP to find the system response of Linear Time-Invariant
[LTI] systems, to arbitrary inputs.
As with signals, convolution exists in both discrete-time and continuous time
domains. The focus of this document is simply on convolution in the discrete time
domain.
Assume a system with
1. Impulse response of h (n)
2. Input forcing signal x (n)
3. Output response y (n)

We symbolically write the system response of the convolution of two sequences as


y (n)= x(n)*h(n).
This is equivalent to
y (n)= (0,N-1) (x(k) * h(n-k)),
Where n varies from 0,1,2,3...N-1.

If we have the following sequences :-


1. Impulse response of h[n] of length N
2. Input forcing signal x[n] of length M
3. And are required to find out the value of the output system response y[n].
4. You are supposed to use the convolution of x[n] and h[n] to get y[n].
5. y (n) = convolution(x(n) ,h(n)) = x(n)*y(n)
6. y (n) is of length M+N-1

PROGRAM:-

clc;
clear all;
close all;
x1 = input('Enter First sequence x1(n)[] : ');
t1 = input('Enter Origin location Of Sequence x1 : ');
x2 = input('Enter Second sequence x2(n)[] : ');
t2 = input('Enter Origin location Of Sequence x2 : ');
l1 = length(x1); %length of sequence x1
l2 = length(x2); %length of sequence x2
ln = l1+l2-1; %length of convoluted sequence
y = conv(x1,x2); % performing convolution using conv() function
a = t1+l1-1;
t = t1:a;
subplot(3,1,1);
stem(t,x1);
xlabel('Time');
ylabel('Amplitude');
title('x1');
a = t2+l2-1;
t = t2:a;
subplot(3,1,2);
stem(t,x2);
xlabel('Time');
ylabel('Amplitude');
title('x2');
tn = t1+t2;
a = tn+ln-1;
t = tn:a;
subplot(3,1,3);
disp('Convoluted Sequence ');
disp(y); % For printing the convoluted output in MATLAB command window
stem(t,y); % For plotting the convoluted output in MATLAB graph window
xlabel('Time');
ylabel('Amplitude');
title('Convoluted Sequence');

OUTPUT:
Enter First sequence x1(n)[] : [1,2,1]
Enter Origin location Of Sequence x1 : -1
Enter Second sequence x2(n)[] : [1,0,2]
Enter Origin location Of Sequence x2 : 0
Convoluted Sequence
1 2 3 4 2
CONCLUSION:

Thus,program to evaluate the linear convolution between two sequences


execute successfully.

You might also like