50% found this document useful (2 votes)
2K views

Matlab Code For Overlap Add Function

This MATLAB code implements an overlap-add method to convolve two sequences. It takes in two sequences as inputs, plots them, then performs overlap-add convolution on them. The output of the convolution is plotted. Overlap-add convolution is performed by breaking the sequences into blocks, zero-padding them, convolving each block, and summing the results.

Uploaded by

Neha Karthikeyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
2K views

Matlab Code For Overlap Add Function

This MATLAB code implements an overlap-add method to convolve two sequences. It takes in two sequences as inputs, plots them, then performs overlap-add convolution on them. The output of the convolution is plotted. Overlap-add convolution is performed by breaking the sequences into blocks, zero-padding them, convolving each block, and summing the results.

Uploaded by

Neha Karthikeyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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