12
20/10/2015 Acoustic Echo Cancellation (AEC) MATLAB & Simulink Example http://www.mathworks.com/help/dsp/examples/acousticechocancellationaec.html?refresh=true 1/12 Open This Example Acoustic Echo Cancellation (AEC) This example shows how to apply adaptive filters to acoustic echo cancellation (AEC). Author(s): Scott C. Douglas Introduction The Room Impulse Response The NearEnd Speech Signal The FarEnd Speech Signal The Microphone Signal The FrequencyDomain Adaptive Filter (FDAF) Echo Return Loss Enhancement (ERLE) Effects of Different Step Size Values Echo Return Loss Enhancement Comparison Introduction Acoustic echo cancellation is important for audio teleconferencing when simultaneous communication (or fullduplex transmission) of speech is necessary. In acoustic echo cancellation, a measured microphone signal d(n) contains two signals: the nearend speech signal v(n) the farend echoed speech signal dhat(n) The goal is to remove the farend echoed speech signal from the microphone signal so that only the nearend speech signal is transmitted. This example has some sound clips, so you might want to adjust your computer's volume now. The Room Impulse Response First, we describe the acoustics of the loudspeakertomicrophone signal path where the speakerphone is located. We can use a long finite impulse response filter to describe these characteristics. The following sequence of commands generates a random impulse response that is not unlike what a conference room would exhibit assuming a system sampling rate of fs = 16000 Hz. fs = 16000; M = fs/2 + 1; frameSize = 8192; [B,A] = cheby2(4,20,[0.1 0.7]); IIR = dsp.IIRFilter('Numerator', [zeros(1,6) B], 'Denominator', A); FVT = fvtool(IIR); % Analyze the filter FVT.Color = [1 1 1];

Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

  • Upload
    logos

  • View
    143

  • Download
    1

Embed Size (px)

DESCRIPTION

free

Citation preview

Page 1: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 1/12

Open This Example

Acoustic Echo Cancellation (AEC)

This example shows how to apply adaptive filters to acoustic echo cancellation (AEC).

Author(s): Scott C. Douglas

Introduction

The Room Impulse Response

The Near­End Speech Signal

The Far­End Speech Signal

The Microphone Signal

The Frequency­Domain Adaptive Filter (FDAF)

Echo Return Loss Enhancement (ERLE)

Effects of Different Step Size Values

Echo Return Loss Enhancement Comparison

IntroductionAcoustic echo cancellation is important for audio teleconferencing when simultaneous communication (or full­duplextransmission) of speech is necessary. In acoustic echo cancellation, a measured microphone signal d(n) contains twosignals:

the near­end speech signal v(n)

the far­end echoed speech signal dhat(n)

The goal is to remove the far­end echoed speech signal from the microphone signal so that only the near­end speechsignal is transmitted. This example has some sound clips, so you might want to adjust your computer's volume now.

The Room Impulse ResponseFirst, we describe the acoustics of the loudspeaker­to­microphone signal path where the speakerphone is located. Wecan use a long finite impulse response filter to describe these characteristics. The following sequence of commandsgenerates a random impulse response that is not unlike what a conference room would exhibit assuming a systemsampling rate of fs = 16000 Hz.

fs = 16000;M = fs/2 + 1;frameSize = 8192;

[B,A] = cheby2(4,20,[0.1 0.7]);IIR = dsp.IIRFilter('Numerator', [zeros(1,6) B], 'Denominator', A);

FVT = fvtool(IIR);  % Analyze the filterFVT.Color = [1 1 1];

Page 2: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 2/12

H = step(IIR, ...    (log(0.99*rand(1,M)+0.01).*sign(randn(1,M)).*exp(‐0.002*(1:M)))');H = H/norm(H)*4;    % Room Impulse ResponsefirRoom = dsp.FIRFilter('Numerator', H');

fig = figure;plot(0:1/fs:0.5, H);xlabel('Time [sec]');ylabel('Amplitude');title('Room Impulse Response');fig.Color = [1 1 1];

Page 3: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 3/12

The Near­End Speech SignalThe teleconferencing system's user is typically located near the system's microphone. Here is what a male speechsounds like at the microphone.

load nearspeech

AP              = dsp.AudioPlayer('SampleRate', fs);nearSpeechSrc   = dsp.SignalSource('Signal',v,'SamplesPerFrame',frameSize);nearSpeechScope = dsp.TimeScope('SampleRate', fs, ...                    'TimeSpan', 35, ...                    'YLimits', [‐1.5 1.5], ...                    'BufferLength', length(v), ...                    'Title', 'Near‐End Speech Signal', ...                    'ShowGrid', true);

% Stream processing loopwhile(~isDone(nearSpeechSrc))    % Extract the speech samples from the input signal    nearSpeech = step(nearSpeechSrc);    % Send the speech samples to the output audio device    step(AP, nearSpeech);    % Plot the signal    step(nearSpeechScope, nearSpeech);end

Page 4: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 4/12

The Far­End Speech SignalNow we describe the path of the far­end speech signal. A male voice travels out the loudspeaker, bounces around inthe room, and then is picked up by the system's microphone. Let's listen to what his speech sounds like if it is picked upat the microphone without the near­end speech present.

Page 5: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 5/12

load farspeechfarSpeechSrc    = dsp.SignalSource('Signal',x,'SamplesPerFrame',frameSize);farSpeechSink   = dsp.SignalSink;farSpeechScope  = dsp.TimeScope('SampleRate', fs, ...                    'TimeSpan', 35, ...                    'YLimits', [‐0.5 0.5], ...                    'BufferLength', length(x), ...                    'Title', 'Far‐End Speech Signal', ...                    'ShowGrid', true);

% Stream processing loopwhile(~isDone(farSpeechSrc))    % Extract the speech samples from the input signal    farSpeech = step(farSpeechSrc);    % Add the room effect to the far‐end speech signal    farSpeechEcho = step(firRoom, farSpeech);    % Send the speech samples to the output audio device    step(AP, farSpeechEcho);    % Plot the signal    step(farSpeechScope, farSpeech);    % Log the signal for further processing    step(farSpeechSink, farSpeechEcho);end

The Microphone Signal

Page 6: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 6/12

The signal at the microphone contains both the near­end speech and the far­end speech that has been echoedthroughout the room. The goal of the acoustic echo canceler is to cancel out the far­end speech, such that only thenear­end speech is transmitted back to the far­end listener.

reset(nearSpeechSrc);farSpeechEchoSrc = dsp.SignalSource('Signal', farSpeechSink.Buffer, ...                    'SamplesPerFrame', frameSize);micSink         = dsp.SignalSink;micScope        = dsp.TimeScope('SampleRate', fs,...                    'TimeSpan', 35, ...                    'YLimits', [‐1 1], ...                    'BufferLength', length(x), ...                    'Title', 'Microphone Signal', ...                    'ShowGrid', true);

% Stream processing loopwhile(~isDone(farSpeechEchoSrc))    % Microphone signal = echoed far‐end + near‐end + noise    micSignal = step(farSpeechEchoSrc) + step(nearSpeechSrc) + ...                    0.001*randn(frameSize,1);    % Send the speech samples to the output audio device    step(AP, micSignal);    % Plot the signal    step(micScope, micSignal);    % Log the signal    step(micSink, micSignal);end

Page 7: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 7/12

The Frequency­Domain Adaptive Filter (FDAF)The algorithm that we will use in this example is the Frequency­Domain Adaptive Filter (FDAF). This algorithm is veryuseful when the impulse response of the system to be identified is long. The FDAF uses a fast convolution technique tocompute the output signal and filter updates. This computation executes quickly in MATLAB®. It also has improvedconvergence performance through frequency­bin step size normalization. We'll pick some initial parameters for thefilter and see how well the far­end speech is cancelled in the error signal.

Page 8: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 8/12

% Construct the Frequency‐Domain Adaptive FilterFDAF    = dsp.FrequencyDomainAdaptiveFilter('Length', 2048, ...            'StepSize', 0.025, ...            'InitialPower', 0.01, ...            'AveragingFactor', 0.98, ...            'Method', 'Unconstrained FDAF');

AECScope1   = dsp.TimeScope(4, fs, ...                'LayoutDimensions', [4,1], ...                'TimeSpan', 35, ...                'BufferLength', length(x));

AECScope1.ActiveDisplay = 1;AECScope1.ShowGrid      = true;AECScope1.YLimits       = [‐1.5 1.5];AECScope1.Title         = 'Near‐End Speech Signal';

AECScope1.ActiveDisplay = 2;AECScope1.ShowGrid      = true;AECScope1.YLimits       = [‐1.5 1.5];AECScope1.Title         = 'Microphone Signal';

AECScope1.ActiveDisplay = 3;AECScope1.ShowGrid      = true;AECScope1.YLimits       = [‐1.5 1.5];AECScope1.Title         = 'Output of Acoustic Echo Canceller mu=0.025';

AECScope1.ActiveDisplay = 4;AECScope1.ShowGrid      = true;AECScope1.YLimits       = [0 50];AECScope1.YLabel        = 'ERLE [dB]';AECScope1.Title         = 'Echo Return Loss Enhancement mu=0.025';

% Near‐end speech signalrelease(nearSpeechSrc);nearSpeechSrc.SamplesPerFrame = frameSize;

% Far‐end speech signalrelease(farSpeechSrc);farSpeechSrc.SamplesPerFrame = frameSize;

% Far‐end speech signal echoed by the roomrelease(farSpeechEchoSrc);farSpeechEchoSrc.SamplesPerFrame = frameSize;

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 lossenhancement (ERLE), which is a smoothed measure of the amount (in dB) that the echo has been attenuated. Fromthe plot, we see that we have achieved about a 35 dB ERLE at the end of the convergence period.

Page 9: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 9/12

firERLE1 = dsp.FIRFilter('Numerator', ones(1,1024));firERLE2 = clone(firERLE1);setfilter(FVT,firERLE1);

micSrc = dsp.SignalSource('Signal', micSink.Buffer, ...    'SamplesPerFrame', frameSize);

% Stream processing loop ‐ adaptive filter step size = 0.025while(~isDone(nearSpeechSrc))    nearSpeech = step(nearSpeechSrc);    farSpeech = step(farSpeechSrc);    farSpeechEcho = step(farSpeechEchoSrc);    micSignal = step(micSrc);    % Apply FDAF    [y,e] = step(FDAF, farSpeech, micSignal);    % Send the speech samples to the output audio device    step(AP, e);    % Compute ERLE    erle = step(firERLE1,(e‐nearSpeech).^2)./ ...        (step(firERLE2, farSpeechEcho.^2));    erledB = ‐10*log10(erle);    % Plot near‐end, far‐end, microphone, AEC output and ERLE    step(AECScope1, nearSpeech, micSignal, e, erledB);end

Page 10: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 10/12

Effects of Different Step Size ValuesTo get faster convergence, we can try using a larger step size value. However, this increase causes another effect, thatis, the adaptive filter is "mis­adjusted" while the near­end speaker is talking. Listen to what happens when we choose astep size that is 60% larger than before.

Page 11: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 11/12

% Change the step size value in FDAFreset(FDAF);FDAF.StepSize = 0.04;

AECScope2 = clone(AECScope1);AECScope2.ActiveDisplay = 3;AECScope2.Title = 'Output of Acoustic Echo Canceller mu=0.04';AECScope2.ActiveDisplay = 4;AECScope2.Title = 'Echo Return Loss Enhancement mu=0.04';

reset(nearSpeechSrc);reset(farSpeechSrc);reset(farSpeechEchoSrc);reset(micSrc);reset(firERLE1);reset(firERLE2);

% Stream processing loop ‐ adaptive filter step size = 0.04while(~isDone(nearSpeechSrc))    nearSpeech = step(nearSpeechSrc);    farSpeech = step(farSpeechSrc);    farSpeechEcho = step(farSpeechEchoSrc);    micSignal = step(micSrc);    % Apply FDAF    [y,e] = step(FDAF, farSpeech, micSignal);    % Send the speech samples to the output audio device    step(AP, e);    % Compute ERLE    erle = step(firERLE1,(e‐nearSpeech).^2)./ ...        (step(firERLE2, farSpeechEcho.^2));    erledB = ‐10*log10(erle);    % Plot near‐end, far‐end, microphone, AEC output and ERLE    step(AECScope2, nearSpeech, micSignal, e, erledB);end

Page 12: Acoustic Echo Cancellation (AEC) - MATLAB & Simulink Example

20/10/2015 Acoustic Echo Cancellation (AEC) ­ MATLAB & Simulink Example

http://www.mathworks.com/help/dsp/examples/acoustic­echo­cancellation­aec.html?refresh=true 12/12

Echo Return Loss Enhancement ComparisonWith a larger step size, the ERLE performance is not as good due to the misadjustment introduced by the near­endspeech. To deal with this performance difficulty, acoustic echo cancellers include a detection scheme to tell when near­end speech is present and lower the step size value over these periods. Without such detection schemes, theperformance of the system with the larger step size is not as good as the former, as can be seen from the ERLE plots.