www.pudn.com > ec_matlab.rar > ec.m
%% The Frequency-Domain Adaptive Filter (FDAF)
%
% The algorithm that we will use in this demonstration is the
% Frequency-Domain Adaptive Filter (FDAF). This algorithm is very useful
% when the impulse response of the system to be identified is long. The
% FDAF uses a fast convolution technique to compute the output signal and
% filter updates. This computation executes quickly in MATLAB. It also has
% improved convergence performance through frequency-bin step size
% normalization. We'll pick some initial parameters for the filter and see
% how well the far-end speech is cancelled in the error signal.
fs = 8000;
% x = wavread('far.wav');
% d = wavread('near.wav');
% v = wavread('near_origin.wav');
% x = wavread('1126_far.wav');
% d = wavread('1126_near.wav');
% v = wavread('1126_near_origin.wav');
x = wavread('F.wav');
d = wavread('N.wav');
v = wavread('N_origin.wav');
M = 32; % NLMS adaptive filter order
mu = 0.8; %0.2; % Normalized LMS step size.
Hadapt = adaptfilt.nlms(M,mu,1);
% mu = 0.025;
% W0 = zeros(1,2048);
% del = 0.01;
% lam = 0.98;
% x = x(1:length(W0)*floor(length(x)/length(W0)));
% d = d(1:length(W0)*floor(length(d)/length(W0)));
% Hadapt = adaptfilt.fdaf(2048,mu,1,del,lam);
[y, e] = filter(Hadapt,x,d);
n = 1:length(e);
t = n/fs;
pos = get(gcf,'Position');
set(gcf,'Position',[pos(1), pos(2)-100,pos(3),(pos(4)+85)])
subplot(4,1,1);
plot(t,x(n),'g');
axis([0 20 -1 1]);
ylabel('Amplitude');
title('Far-End Speech Signal');
subplot(4,1,2);
plot(t,d(n),'b');
axis([0 20 -0.2 0.2]);
ylabel('Amplitude');
title('Near-End Speech Signal');
subplot(4,1,3);
plot(t,e(n),'r');
axis([0 20 -0.2 0.2]);
xlabel('Time [sec]');
ylabel('Amplitude');
title('Output of Acoustic Echo Canceller');
set(gcf, 'Color', [1 1 1])
% wavwrite(e, 'out.wav');
% wavwrite(e, '1126_out.wav');
wavwrite(e, 'O.wav');
%% Echo Return Loss Enhancement (ERLE)
%
% Since we have access to both the near-end and far-end speech
% signals, we can compute the echo return loss enhancement
% (ERLE), which is a smoothed measure of the amount (in dB)
% that the echo has been attenuated. From the plot, we see
% that we have achieved about a 30 dB ERLE at the end of the
% convergence period.
Hd2 = dfilt.dffir(ones(1,1000));
erle = filter(Hd2,(e-v(1:length(e))).^2)./(filter(Hd2,(d(1:length(e))-v(1:length(e))).^2));
erledB = -10*log10(erle);
subplot(4,1,4);
plot(t,erledB);
set(gca,'YTick',[0 3 6 9 12 15 30]);
grid on;
axis([0 20 0 30]);
xlabel('Time [sec]');
ylabel('ERLE [dB]');
title('Echo Return Loss Enhancement');
set(gcf, 'Color', [1 1 1])