You are on page 1of 2

MATLAB CODE FOR OVERLAP ADD FUNCTION

clc
close all;
clear all;
xn=input ('Enter the Largest Sequence(x(n)):');
hn=input ('Enter the Second Sequence(h(n)):');

% Plot Input-1
subplot(221);
stem(xn);
xlabel('Time Index');
ylabel('Amplitude');
title('INPUT SEQUENCE1 x(n)');

% Plot Input-2
subplot(222);
stem(hn);
xlabel('Time Index');
ylabel('Amplitude');
title('INPUT SEQUENCE2 h(n)');

% Overlap ADD
m=length(xn);
l=length(hn);
d= m;
g=(2*l)-1;
c=0;


for n=1:(m/l)
d= d-l;
end

xn((m+1):(m+l-d))=zeros;
hn((l+1):((2*l)-1))=zeros;
xt=zeros(1,g);
yn=zeros(1,(l+m-1));
for k=1:l:m

c=c+1;

x1=xn(k:l+k-1);
x1((l+1):(g))=zeros;
xf=[x1(1),x1(g:-1:2)];
p=xf*hn';
xt(1)= p;


for s=1:(g-1)
xf=[xf(g),xf];
xf=xf(1:g);
p=xf*hn';
xt(s+1)=p;

end

xt((g+1):(l+m-1))=zeros;
xt=circshift(xt,[0 ((c-1)*l)]);
yn=yn+xt;
end


% Plot Output
subplot(223);
stem(yn);
xlabel('Time Index');
ylabel('Amplitude');
title('OUTPUT SEQUENCE y(n)');

You might also like