% Demo overlap save method of convolution,
% compare with direct convolution sum
echo on
L = 512;
% Design lowpass FIR filter
P = 57; % FIR filter length
wp = .3; % passband corner freq. wp*pi = radian freq.
ws = .4; % stopband corner freq. ws*pi = radian freq.
Wp = 1.0; % passband ripple weighting
Ws = 10.0; % stopband ripple weighting
h = firpm(P-1, [0, wp ws 1.0], [1 1 0 0 ], [Wp Ws]);
stem(h)
title('FIR Filter Coefficients');
pause
% Load in audio data and display it
figure(1)
x = wavread('voice2.wav');
r = input('Input the window index (-1 to stop) r= ');
while r>=0
plot(x(r*(L-P+1)+1:r*(L-P+1)+L));
title('A Window of the voice data');
r = input('Input the window index (-1 to stop) r= ');
end
% form complex data vector for fair comparison
x = x + j*x;
% compute y = h*x using overlap save
tic
y1 = real(ovrlpsav(x, h, L));
t = toc;
disp(['The ellapsed time for overlap save is: ',num2str(t),' seconds.'])
wavwrite(y1, 11025, 16, 'fltvoic1.wav');
pause
tic
y2=real(firfilt(x, h));
t = toc;
disp(['The ellapsed time for conventional FIR filtering is: ',num2str(t),' seconds.'])
wavwrite(y2, 11025, 16, 'fltvoic2.wav');
% Plot the filtered data
figure(2)
r = input('Input the window index (-1 to stop) r= ');
while r>=0
plot(y1(r*(L-P+1)+1:r*(L-P+1)+L));
title('A Window of the filtered voice data');
r = input('Input the window index (-1 to stop) r= ');
end
echo off