Overlap Add Method: Input Input Input Input Modulo

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Overlap Add Method

clc
clear
disp('Consider longer sequence as x(n) and shorter one as h(n)');
l=input('Enter the number elements in x(n)');
x=input('Enter x1(n):');
N=input('Enter the number elements in h(n)');
h=input('Enter h(n):');
k=modulo(l,N);
if k~=0 then
for d=(1):N-k
x(l+d)=0;
end
end
L=length(x);
m=L/N;
M=L+N-1;
p=1;c=0;
Y=zeros(1,L+N-1);
H=[h,zeros(1,N-1)];
for a=1:m
x1=zeros(N);
j=1;
for b=p:p+N-1;
x1(j)=x(b);
j=j+1;
end
X=[x1',zeros(1,N-1)];
H1=fft(H);
X1=fft(X);
y=H1.*X1;
y1=fft(y,1);
p=p+N;
y2=circshift([y1,zeros(1,(m-1)*N)],c*N);
c=c+1;
Y=Y+y2;
end
disp('The linear convolution Y(n) is:');
disp(Y);

Overlap Save Method


clc
clear
disp('Consider longer sequence as x(n) and shorter one as h(n)');
n=input('Enter the number elements in x(n)');
x=input('Enter x1(n):');
M=input('Enter the number elements in h(n)');
h=input('Enter h(n):');
N=input('Enter the size of DFT to be performed');
L=N-M+1;
H=[h,zeros(1,L-1)];
X=[zeros(1,M-1),x,zeros(1,M-1)];
Y=zeros(1,n+M-1);
a=length(X);
p=1;i=1;
while p+N-1<=a
x1=zeros(N);
j=1;
for b=p:p+N-1;
x1(j)=X(b);
j=j+1;
end
H1=fft(H);
X1=fft(x1');
y=H1.*X1;
y1=fft(y,1);
p=p+L;
c=0;
for c=M-1:N-1
Y(i)=y1(c+1);
i=i+1;
end
end
disp('The linear convolution Y(n) is:');
disp(Y);

You might also like