Blogger Widgets

Wednesday, 18 April 2012

Convolution using overlap Add method : -

Function for Circular convolution:-


function y=mycirconv(x,h)
lx=length(x);
lh=length(h);

l=max(lx,lh);

X=[x zeros(1,l-lx)];

H=zeros(l);

H(1:lh)=h;

for j=1:l-1

for i=1:l-1

H(i+1,j+1)=H(i,j);

end

H(1,j+1)=H(l,j);

end

y=H*X';


N.B.:-Save this program by naming same as the function name.  


Main Program:-
 
clc;
clear all;
close all;
x=input('Enter 1st sequence x(n)');
h=input('Enter 2nd sequence h(n)');
L=input('Enter length of each block L =');
subplot (2,2,1);
stem(x);title('1st sequence x(n)');
subplot (2,2,2);
stem(h);title('2nd sequence h(n)');
Nx=length(x);
M=length(h);
M1=M-1;
R=rem(Nx,L);
N=L+M1;
x=[x zeros(1,L-R)];
h=[h zeros(1,N-M)];
K=floor(Nx/L);
y=zeros(K+1,N);
z=zeros(1,M1);
for k=0:K
xp=x(L*k+1:L*k+L);
xk=[xp z];
y(k+1,:)=mycirconv(xk,h);
end
p=L+M1;
for i=1:K
y(i+1,1:M-1)=y(i,p-M1+1:p)+y(i+1,1:M-1);
end
z1=y(:,1:L)';
y=(z1(:))'
subplot (2,2,3:4);
stem(y);
title('Convolution using Overlap Add method');


Figure:-  



2 comments

Bluedot

code is not working

fuck u bitch

u fucker code is not working

Post a Comment