You are on page 1of 6

EX.

NO:2
LINEAR CONVOLUTION

AIM:

To Perform Linear Convolution in matlab.

Software Required:

MATLAB 7.0

Theory:

The output y[n] of a LTI (linear time invariant) system can be obtained by convolving the
input x[n] with the systems impulse response h[n].

The convolution sum is y (n) x(n) * h(n) x[k ] h[n k ] where
k
x(n) and h(n) can be

both finite or infinite duration sequences.


Even if one (or both) of the sequences is infinite (say, h[n] =(0.9)n u[n] ), we can
analytically evaluate the convolution formula to get a functional form (closed form solution)
of y[n].
If both the sequences are of finite duration, then we can use the MATLAB function conv to
evaluate the convolution sum to obtain the output y[n]. Convolution is implemented as
polynomial multiplication (refer MATLAB help).
The length of y[n] = xlength + hlength -1.The conv function assumes that the two sequences
begin at n=0 and is invoked by
y=conv(x,h). Even if one of the sequences begin at other values of n, say n=-3,or
n=2; then we need to provide a beginning and end point to y[n] which are ybegin=xbegin+hbegin
and yend=xend+hend respectively.

Program:

close all;

clear all;

clc;

%CONVOLUTION IN TIME DOMAIN

x=input('enter the input sequence x(n)');


h=input('enter the input sequence h(n)');

y=conv(x,h);

subplot(3,1,1);

stem(x);

xlabel('time');

ylabel('amplitude');

title('Input Sequence x(n)');

subplot(3,1,2);

stem(h);

xlabel('time');

ylabel('amplitude');

title('Input Sequence h(n)');

subplot(3,1,3);

stem(y);

xlabel('time');

ylabel('amplitude');

title('Convoluted Output Sequence Using Time Domain');

%CONVOLUTION IN FREQUENCY DOMAIN

N1=length(x);

N2=length(h);

N=N1+N2-1;

x=[x zeros(1,N2-1)]; %Zero padding to x

h=[h zeros(1,N1-1)]; %Zero padding to h

X=fft(x,N);

H=fft(h,N);

Y=X.*H;
y=ifft(Y,N);

figure

subplot(3,1,1);

stem(x);

xlabel('time');

ylabel('amplitude');

title('Input Sequence x(n)');

subplot(3,1,2);

stem(h);

xlabel('time');

ylabel('amplitude');

title('Input Sequence h(n)');

subplot(3,1,3);

stem(y);

xlabel('time');

ylabel('amplitude');

title('Convoluted Output Sequence using Frequency domain ');

OUTPUT:
MANUAL CALCULATION:
OUTPUT PLOTS:
RESULT:

You might also like