You are on page 1of 9

Digital signal processing

LAB Fat

Name : S V JAGADEESH KONA

REG : 18BEC2012

L35 +L36

Q) write a matlab program to convolute discrete time signals

Aim : using linear convolution and circular convolution

close all

clear all

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

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

m=length(x);

n=length(h);

subplot(4,1,1)

stem(1:m,x,'fill','r')

grid on;

title('input sequence, x(n)=')

xlabel('time n------>')

ylabel('amplitude----->')

subplot(4,1,2)

stem(1:n,h,'fill','r')

grid on;

title('impulse sequence, h(n)=')

xlabel('time n------>')

ylabel('amplitude----->')
%------linear convolution using inbuilt command------------------------%

v=conv(x,h)

l=m+n-1;

subplot(4,1,3)

stem(1:l,v,'fill','r')

grid on;

title('output sequence using inbuilt command, v(n)=')

xlabel('time n------>')

ylabel('amplitude----->')

%--------linear convolution using 'for' loop------------------------------%

X=zeros(1,l);

H=zeros(1,l);

X(1:m)=x;

H(1:n)=h;

for i=1:l

Y(i)=0;

for j=1:i

Y(i)=Y(i)+X(j)*H(i-j+1);

end

end

subplot(4,1,4)

stem(1:l,Y,'fill','r')

grid on;

title('output sequence using loop, Y(n)=')


xlabel('time n------>')

ylabel('amplitude----->')

imput sequence :

x[n]= [ 1 2 2 1]

h[n] = [ 5 6 8 9 ]

output y[n] = [ 5 16 30 42 40 26 9]
Circular convolution

clc;

close all;

x=input('Enter x(n):\n');

h=input('Enter h(n):\n');

m=length(x);%length of sequence x(n)

n=length(h);%length of sequence h(n)

N=max(m,n);%length of output sequence y(n)

%For equating both sequence length

x=[x,zeros(1,N-m)];

h=[h,zeros(1,N-n)];

for n=1:N

Y(n)=0;

for i=1:N

j=n-i+1;

if(j<=0)

j=N+j;

end

Y(n)=[Y(n)+x(i)*h(j)];

end

end

n=0:N-1;%Range of all Sequences

subplot(311)

disp('First Sequence x(n) is:')

disp(x)
stem(n,x)

xlabel('n')

ylabel('x(n)')

title('First Sequence')

grid on;

subplot(312)

disp('Second Sequence h(n) is:')

disp(h)

stem(n,h)

xlabel('n')

ylabel('h(n)')

title('Second Sequence')

grid on;

subplot(313)

disp('Convoluted Sequence Y(n) is:')

disp(Y)

stem(n,Y)

xlabel('n')

ylabel('Y(n)')

title('Circular Convoluted Sequence')

grid on;
input sequence

x[n] = [1 2 2 1]

h[n] = [ 5 6 8 9 ]

y[n]=[ 45 42 39 42]
Manual calculations :

Linear convolution

You might also like