Professional Documents
Culture Documents
LAB Fat
REG : 18BEC2012
L35 +L36
close all
clear all
m=length(x);
n=length(h);
subplot(4,1,1)
stem(1:m,x,'fill','r')
grid on;
xlabel('time n------>')
ylabel('amplitude----->')
subplot(4,1,2)
stem(1:n,h,'fill','r')
grid on;
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;
xlabel('time n------>')
ylabel('amplitude----->')
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;
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');
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
subplot(311)
disp(x)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('First Sequence')
grid on;
subplot(312)
disp(h)
stem(n,h)
xlabel('n')
ylabel('h(n)')
title('Second Sequence')
grid on;
subplot(313)
disp(Y)
stem(n,Y)
xlabel('n')
ylabel('Y(n)')
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