Overlap Save Method
CODE
clc;
clear all;
x=input('Enter 1st sequence X(n)= ');
h=input('Enter 2nd sequence H(n)= ');
L=input('Enter length of each block L = ');
% Code to plot X(n)
subplot (2,2,1);
stem(x);
stem(x,'blue');
xlabel ('n---->');
ylabel ('Amplitude ---->');
title('X(n)');
%Code to plot H(n)
subplot (2,2,2);
stem(h);
stem(h,'black');
xlabel ('n---->');
ylabel ('Amplitude ---->');
title(' H(n)');
% Code to perform Convolution using Overlap Save Method
M=length(h);
lx=length(x);
r=rem(lx,L); %calculating positions to be padded in Xn
x1=[x zeros(1,L-r)]; %zero padding input sequence
nr=(length(x1))/L; %calculating number of data blocks
h1=[h zeros(1,L-1)]; %zero padding filter
for k=1:nr
Ma(k,:)=x1(((k-1)*L+1):k*L)
if k==1
Ma1(k,:)=[zeros(1,M-1) Ma(k,:)];
else
Ma1(k,:)=[Ma(k-1,(L-M+2):L) Ma(k,:)];
end
Ma2(k,:)=ifft(fft(Ma1(k,:)).*fft(h1));
end
Ma3=Ma2(:,M:(L+M-1));
y1=Ma3';
y=y1(:)'
% Representation of the Convoled Signal
subplot (2,2,3:4);
stem(y,'red');
xlabel ('n---->');
ylabel ('Amplitude ---->');
title ('Convolved Signal');
% Add title to the Overall Plot
ha = axes ('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0
1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text (0.5, 1,'\bf Convolution using Overlap Save Method
','HorizontalAlignment','center','VerticalAlignment', 'top')
Overlap Add Method
CODE
clc;
clear all;
Xn=input('Enter 1st Sequence X(n)= ');
Hn=input('Enter 2nd Sequence H(n)= ');
L=input('Enter length of each block L = ');
% Code to plot X(n)
subplot (2,2,1);
stem(Xn);
xlabel ('n---->');
ylabel ('Amplitude ---->');
title(' X(n)');
%Code to plot H(n)
subplot (2,2,2);
stem(Hn,'red');
xlabel ('n---->');
ylabel ('Amplitude ---->');
title(' H(n)');
% Code to perform Convolution using Overlap Add
Method
NXn=length(Xn);
M=length(Hn);
M1=M-1;
R=rem(NXn,L);
N=L+M1;
Xn=[Xn zeros(1,L-R)];
Hn=[Hn zeros(1,N-M)];
K=floor(NXn/L);
y=zeros(K+1,N);
z=zeros(1,M1);
for k=0:K
Xnp=Xn(L*k+1:L*k+L);
Xnk=[Xnp z];
y(k+1,:)=mycirconv(Xnk,Hn); %Call the mycirconv
function.
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(:))'
%Code to plot the Convolved Signal
subplot (2,2,3:4);
stem(y,'black');
xlabel ('n---->');
ylabel ('Amplitude ---->');
title('Convolved Signal');
% Add title to the Overall Plot
ha = axes ('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0
1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text (0.5, 1,'\bf Convolution using Overlap Add Method
','HorizontalAlignment','center','VerticalAlignment', 'top')
Frequency resolution analysis
CODE
l = input('Enter L');
w = ones(1,1);
n = 0:1:l-1;
N = 1024;
w0 = pi/12; w1 = pi/6 ; w2 = pi/4;
x = cos(w0*n) + cos(w1*n) + cos(w2*n);
y = x.*w;
y = [y zeros(1,N-1)];
z = zeros(1,N);
for k = 1:N
for l=1 :N
z(k) = z(k)+ y(l)*exp(-2*i*pi*k*l/N);
end
end
plot(abs(z));
Figure 2 : L = 25 Figure 1 : L = 50
Figure 3 : L = 100