You are on page 1of 7

Name: U Yuva Kumar

Reg no: 3122 21 3002 115

Date: 03/04/2023
Expt no.: 03

LINEAR FILTERING USING OVERLAP ADD AND


OVERLAP SAVE METHOD

Aim:
To write a MATLAB Program to demonstrate linear filtering via overlap save and overlap
add methods.

Software used:
MATLAB Interpreter – R2022 b version

1)Overlap Save Method


The overlap save procedure cuts the signal up into equal length segments with some overlap. Then it
takes the DFT of the segments and saves the parts of the convolution that correspond to the circular
convolution. Because there are overlapping sessions , it is like the input is copied and therefore there
is not lost information in throwing away the parts of the linear convolution.

Algorithm
1.Let L and M represent the length of the input sequence x(n) and impulse sequence h(n) respectively.
2.Add M-1 leading zeros to the input sequence and L+M-1 trailing zeros to the shorter sequence.
3.Divide the input sequence into segments containing 2M-1 samples. Each segment should contain M-
1 samples from the previous segments.
4.Perform Circular Convolution of each segments with impulse sequence matrix.
5.Discard the first M-1 samples from each of the resultant sequence.
6.Finally concatenate the remaining samples to get the linearly convolved output.

CODE:
clc; clear all; close all;
x=input('Enter the input sequence: ');
N=length(x);
a=0:N-1;
h=input('Enter the impulse sequence: ');
M=length(h);
b=0:M-1;
subplot(3,1,1);
stem(a,x);
Name: U Yuva Kumar
Reg no: 3122 21 3002 115

xlabel('Time');
ylabel('Amplitude');
title('Input sequence')
subplot(3,1,2);
stem(b,h);
xlabel('Time');
ylabel('Amplitude');
title('Impulse sequence');
h=[h zeros(1,M-1)];
L=length(h); % Length of sub-block

K1=ceil(N/M)+1; % No. of blocks


N1=L+M*(K1-1); % No. of samples after padding zeros
x1=[zeros(1,M-1) x zeros(1,N1-(M-1)-N)];
x2=[];
y1=[];
y2=[];
for i=1:K1
x2=x1(M*(i-1)+1:M*(i-1)+L);
y1=circ_conv(x2,h);
y2=[y2 y1(M:L)];
end
c=0:length(y2)-1;
subplot(3,1,3);
stem(c,y2);
xlabel('Time');
ylabel('Amplitude');
title('Overlap Save Method');
disp('The overlap save output is:'); disp(y2);

%Function yo find circular convolution


function[Y] = circ_conv(X,H)
m=length(X);
n=length(H);
N=max(m,n);
X=[X zeros(1,N-m)];

H=[H zeros(1,N-n)];
Y=zeros(1,N);
for n=1:N
for m=1:N
j=mod(n-m,N)
j=j+1
Y(n)=Y(n)+X(m)*H(j)
end
end
end
Name: U Yuva Kumar
Reg no: 3122 21 3002 115

Output:
Enter the first sequence :

[3 1 2 2 1 1 5]

Enter the second sequence:

[1 1 1]

Output of overlap save is

1 3 6 9 12 15 11 6 0

Inference:
From the above program , we can infer that how the linearly convolved output is obtained by
performing sectioned circular convolution.
Name: U Yuva Kumar
Reg no: 3122 21 3002 115

2)Overlap Add Method


The overlap add procedure cuts the signal up into equal segments with no overlap. Then it zero pads
the sequence and takes the DFT of the segments. Part of the convolution result corresponds to the
circular convolution. The tails that do not correspond to the circular convolution are added to the
adjoining tail of the previous and subsequent sequence.

Algorithm:
1.Let L and M represent the length of the input sequence x(n) and impulse sequence h(n) respectively.
2.Check whether L is an integral multiple of M. If not , zero pad the h(n) sequence so that L=KM.
3.Divide the input sequence x(n) into K non-overlapping segments.
4.Perform Circular Convolution of each segments with impulse sequence matrix.
5.Add the trailing M-1 samples from each of the resultant sequence to the next M-1 leading samples.
6.Finally concatenate the remaining samples to get the linearly convolved output.

Code:
clc; clear all; close all;
x=input('Enter the input sequence: ');
N=length(x);
a=0:N-1;
h=input('Enter the impulse sequence: ');
M=length(h);
b=0:M-1;
subplot(3,1,1);
stem(a,x);
xlabel('Time');
ylabel('Amplitude');
title('Input sequence')
subplot(3,1,2);
stem(b,h);
xlabel('Time');
ylabel('Amplitude');
title('Impulse sequence');
h=[h zeros(1,M-1)];
Name: U Yuva Kumar
Reg no: 3122 21 3002 115

L=length(h); % Length of sub-block

K2=ceil(N/M); % No. of blocks


x2=[x zeros(1,M*K2-N)];
x3=[];
y3=[];
y4=[];
y5=[];
for i=1:K2
x3=[x2(M*(i-1)+1:M*i) zeros(1,M-1)];
y3=circ_conv(x3,h);
y4(i,:)=[zeros(1,(M*(i-1))) y3 zeros(1,M*(K2-i))];

end
y5=sum(y4(:,:));
c=0:length(y5)-1;
subplot(3,1,3);
stem(c,y5);
xlabel('Time');
ylabel('Amplitude');
title('Overlap Add Method');
disp('The overlap add output is:'); disp(y5);

%Function to find circular convolution


function[Y] = circ_conv(X,H)
m=length(X);
n=length(H);
N=max(m,n);
X=[X zeros(1,N-m)];

H=[H zeros(1,N-n)];
Y=zeros(1,N);
for n=1:N
for m=1:N
j=mod(n-m,N)
j=j+1
Y(n)=Y(n)+X(m)*H(j)
end
end
end

Output:

Enter the input sequence: [3 1 2 2 1 1 5]


Enter the impulse sequence: [2 4 0 3]
Y=

2 6 14 23 3 15 0
Name: U Yuva Kumar
Reg no: 3122 21 3002 115

The overlap add output is:


6 14 8 21 13 12 20 23 3 15 0

Inference:
From the above program , we can infer that how the linearly convolved output is obtained by
performing sectioned circular convolution.

Result:
Thus, the programs to demonstrate the process of linear filtering using overlap save and overlap add
is executed and the output is verified.
Name: U Yuva Kumar
Reg no: 3122 21 3002 115

You might also like