Echo Cancellation Using Adaptive Filtering: by Thanis Tridhavee and Steve Vuco
Echo Cancellation Using Adaptive Filtering: by Thanis Tridhavee and Steve Vuco
By
Thanis Tridhavee
And
Steve Vuco
5/4/99
Project Number 6
1
ABSTRACT
algorithm on the Motorola 56K series digital signal processor in an echo cancellation
system. This scheme identifies the frequency response of the echo system so that the
adaptive filter generates an estimate of the echo and subtracts it from a distorted signal so
that the original signal can be recovered. The LMS algorithm design is used extensively
mismatches and is useful to compensate for the imperfection in telephony networks. This
paper shows how the LMS algorithm is useful to solve echo problems. This project is an
processing.
ii
2
TABLE OF CONTENTS
PAGE
Echo Cancellation
Introduction………………………………………………………….. 1-2
1.2 Design Procedure……………………………………………………. 2-5
Design Details……………………………………………………….. 6-7
Design Verification………………………………………………….. 7-8
Conclusion…………………………………………………………… 8
2.1 Introduction…………………………………………………………... 9
2. Cost Analysis…………………………………………………………………. 12
4. References……………………………………………………………………. 20
3
iii
1.1 Introduction
arise for a number of reasons, with the primary reason being an impedance mismatch.
The impedance mismatch occurs when the two-wire network meets the four-wire
network, this interface is known as the hybrid. This impedance mismatch causes some of
the signal energy to be returned to the source as an echo [1]. This can be seen in Figure
The delays between primary and echo signals are directly related to the
transmission distance. For example, if a signal was sent to a satellite that redirected the
signal back to another location on earth, that signal would have a very large time delay
compared to a signal sent to a local switching station and back. Short delays (less than 50
ms) will not affect the quality of the signal as much as longer delays. Delays of this
length are not noticed by the receiver and therefore are not considered an annoyance.
However, these echoes may have an effect on data being transmitted through
A sinusoid will be used as the input signal. The DSP board will create an echo of
the sinusoid and add the echo to the original sinusoidal signal, thus creating a distorted
version of the input signal. The DSP will then use LMS adaptive filtering to estimate the
echo, and remove the echo from the distorted signal creating a reconstructed signal. The
LMS algorithm seeks to minimize the excess mean-square error (MSE) between the echo
signal and the estimated echo. The excess MSE refers to the LMS algorithm fluctuations
about the adaptive filter coefficients after a large number of iterations [1].
4
This project consists of designing and implementing an echo canceling system.
The Motorola 56K series DSP chip is used to simulate the echo creating system and to
implement the adaptive filtering system to cancel the echo in the distorted signal.
Initially, the adaptive filter coefficients are far from the ideal numbers. After several
iterations, the LMS algorithm will update these coefficients to converge on an optimal set
approximate performance specifications before implementation. MSE plots that are called
learning curves in the DSP field will be attained. The learning curves as well as the
magnitude of the frequency response of the adaptive filter coefficients will be used to
determine the performance of our system. Convergence of the adaptive filter coefficients
and the similarity of the coefficient values in simulation and experimentation will also be
of vital significance.
The µ value in the LMS algorithm is an important value in determining the performance
of the echo cancellation. µ must be chosen between zero and twice the inverse total
input power.
Some variables that are kept constant are the echo delay, filter length, standard of
deviation of the additive white gausian noise (AWGN) and echo attenuation.
The sampling rate was determined by using the equation for the Nyquist rate. The
sampling rate used is equivalent to the Nyquist rate. fBL is the band limited frequency,
5
Nyquist Rate=2 *fBL (2)
There are many algorithms that could be used in echo cancellation or adaptive
filtering; most are variations of the least mean squared (LMS) algorithm. Some
variations include normalized LMS (NLMS) and the recursive least squares algorithm
(RLS). The LMS algorithm was chosen because it is the most commonly used algorithm
in echo cancellation and other adaptive filtering applications. LMS is the most
requirements and is also relatively simple compared to the other algorithms. The LMS
algorithm uses relatively few calculations, which makes it suitable for the speeds of the
The LMS algorithm seeks to minimize the excess MSE between the echo and its
output. The communication network in Figure 1 has the necessary signals that are
required by the LMS algorithm. The adaptive LMS equation is given by:
filter coefficients. If µ is large, the filter will converge fast, but could diverge if µ is
too large. When µ is large, the adaptation is quick, but there will be an increase in the
average excess MSE. This excess MSE may be undesirable result. If µ is small, the
6
filter will converge slowly, which is equivalent to the algorithm having “long” memory,
an undesirable quality. Every application will have a different step size that needs to be
convergence and the MSE. The µ value is decided through trial and error so that speed
at which the adaptive filter learns and the excess MSE is obtained within application
requirements. The µ values differs from simulation to real-time because of the inherit
The system equations used by the adaptive filter to determine the error and output
of the filter are listed below. The output of the adaptive filter is found though
convolution of the adaptive filter coefficients w(n) with the input signal x(n).
The error signal e(n) is created from the subtraction of the desired signal from the
Error Signal:
7
f(n) = d(n)+x(n) (7)
= α *x(n-β ) + x(n)
Reconstructed Signal:
After many iterations, the echo signal resembles the output of the adaptive filter
and the reconstructed signal equals the input signal. The input signal is used as an input
to the adaptive filter so that the adaptive filter’s frequency response approximates the
echo system’s frequency response. Then the error signal converges to approximately
zero. The error signal is feedback to the adaptive filter and is used as an input with the
The objective of the adaptive filter is to minimize the MSE between the echo and
estimated echo. Ideally, the error will go to zero after several iterations. The next set of
adaptive filter coefficients is equal to the previous set. This set of filter coefficients
approximates the transfer function that creates the echo. In this case, the hybrid of the
telephone network creates this transfer function that is model on the DSP. The adaptive
coefficients are an estimate of the echo system’s transfer function. The hybrid system
may be nonlinear, but the echo system is modeled as linear time-invariant transfer
function with attenuation and time delay or phase shift. The cancellation is achieved by
making an estimate of the echo and subtracting it from the distorted signal. Our system
8
1.3 Design Details
The system model of our echo cancellation device is shown in Figure 2. The
input signal will be a sinusoidal at 2.0 kHz because telephone voice frequency spectrum
exists from 0-4 kHz. The band limited frequency for telephone transmission is 4 kHz.
Thus the Nyquist rate is set to eight thousand samples per second.
The echo filter uses the original signal to create the echo signal. The transfer
function is chosen to be 0.5*z^-512. This signal will be delayed by 512 samples, which
fifty percent. This is a reasonable approximation for the system that creates the echo of
the input signal. Human hearing has been tested to be intolerable to echo delays of more
The filter is chosen to be 20 taps. This number of taps was chosen for two
reasons. It was small enough to limit processing time, however it was large enough to
show good convergence in the MATLAB simulations. The adaptive filter taps at first are
initialized to the null vector. Figure 3 shows the frequency response of the MATLAB
simulation for the adaptive coefficients after several iterations with a µ value of 0.01. A
learning curve is shown in Figure 4 with the MSE approaching –40 dB after
approximately one hundred iterations. Figure 4 also shows the input signal added to the
echo signal and plotted under it is the reconstructed signal. After approximately a
hundred iterations, the original input signal is restored from the distorted signal. In
Figure 5 the adaptive filter coefficients are shown after several iterations when the
9
adaptive filter has fully been trained. The frequency plots in Figure 3 and adaptive filter
AWGN was used in simulation and in the experiment to simulate actual noise. A
standard deviation of 0.02 was used in simulation and experimentation. For simulation,
the MATLAB AWGN function was used. In experimentation, the samples of the AWGN
from MATLAB were loaded into a file of length 2048. Then that file was used in the
assembly code to add AWGN to the original input signal. AWGN is used because it
The experiment was setup similar to simulation conditions. The system needed a
larger µ value to get similar performance specifications, such as similar adaptive filter
frequency responses and filter coefficients. Through trial and error, a successful µ value
of 0.3 was discovered. In Figure 5, the adaptive filter coefficients are plotted on top of
the simulation adaptive filter coefficients. The coefficients look very similar to each
other after the adaptive filters have been trained after a large number of iterations. If the
implementation of the LMS echo cancellation system did not converge for the µ value
used, then the adaptive filter coefficients were seen to explode to the maximum register
values of +/- 1. In the implementation, a µ value of 0.3 came close to outputting similar
adaptive filter coefficients and responses. The output of the system was verified on the
oscilloscope in comparison with the input signal. Learning curve plots of the actual MSE
were not attainable due to the software’s inability to save the error coefficients to file.
The error signal of the LMS is saved into memory in the assembly code for
approximately 320 samples. The software operating the DSP was incapable of writing
10
the information into a useful file for MATLAB manipulation. However the software did
show the values on the computer screen. In experiment the MSE did descend in the same
fashion as the learning curve in simulation. This was shown during the project
demonstration.
1.5 Conclusions
The LMS algorithm successful cancelled the echo and returned a reconstruction
of the original signal. It identified the echo system’s transfer response within a small
number of iterations. The LMS algorithm is a very powerful and simple tool for echo
value were necessary due to the nonlinear effects that occurred in the experiment. The
nonlinear quantization of the DSP most likely accounted for these effects. A method to
expand the project would be to use an actual system with real echoes. A microphone and
speaker with a box in between them could be used to create the echoes. Also, longer time
delays could be used. Longer time delays would warrant more filter taps and faster DSPs
since the number of calculations increases for the longer filter lengths. The echo
cancellation system that was implemented would be useful in the initialization sequence
of a phone call. The frequency response of the echo system could be identified and used
to compensate for the echo problems. If faster convergence were needed, then the µ
value could be increased cautiously because the system could start to diverge. If a small
MSE was needed, then a small µ could be used, but the learning curve would extend for
a longer time. The more calculation intensive NLMS or RLS algorithm could be used so
that the µ value is calculated within the system without human intervention. Echo
11
cancellation works well if one can estimate the echo delays so that the µ values and
12
STANDARD HARDWARE
2.1 Introduction
A special circuit was assigned to those with primarily software based senior
design projects. The assignment was to design, assemble, and test a timer circuit. The
circuit was to meet certain constraints. The values that were constrained include the clock
voltage, the variance in frequency and high time pulse width. Two specification tests
were also assigned. The objective of these tests was to find the resistor values for given
The use of a linear 555 timer was chosen because it was suggested. The timer
circuit model is given in Figure 6. Variable resistors were used in the circuit to avoid
repeated assembly and disassembly of the circuit. The capacitors used were set to a
constant value.
The model shown in Figure 3 is the astable circuit model given by Motorola
analog IC device data. The external capacitor is charged through Ra and discharged
through Rb. Because of this, the duty cycle is controlled by the ratio of the two resistors.
The duty cycle was specified to be less than fifty percent high. The supply voltage does
not affect the charge and discharge times. The following equations were also given by
13
Period:
Frequency:
Duty Cycle:
DC = Rb/(Ra+2Rb) (13)
Ra minimum:
The standard Ra and Rb values were found to meet the design constraints. The
Capacitor = 0.01 µ F
Frequency = 3700 Hz
The resistor values were found first. Those values were then used to determine
the theoretical values. The values derived from the equations did not match the values
obtained from the experiment. The values for both theoretical and experimental are given
in Table 1. Motorola literature suggested that a duty cycle of less than fifty percent would
be hard to achieve. The Ra value used here was chosen because Ra needs to be close to
Ra minimum. Choosing a small Ra insures that the duty cycle high is kept to a minimum
14
The next step was to determine the values of the specification tests. Ra minimum
was found to be one hundred and sixteen ohms. Ra and Rb were then adjusted to meet
the frequency and pulse width requirements. With the requirements met, the tolerances
were then determined by varying Rb. The values for Ra were varied to test the
specifications again. These resistor tolerance values are listed in Table 2 for each
specification.
2.4 Conclusions
The task of the hardware portion was to determine the resistor values to set the
timer circuit. These goals were met and the values are listed in Table 2.
The theoretical values for the timer circuit did not match the experimental results
well. It appears that when the duty cycle is kept to less than 50%, the linear 555 timer
experiences nonlinear effects. Proper values of the variable resistors Ra and Rb were
Varying the resistors had various effects on the period and pulse width of the
timer. As Rb increased by a small percentage, the pulse width and period increased. A
small decrease in Rb would decrease the period and pulse width. Increases and decreases
in Rb over a small range had very little effect on the duty cycle. In order to vary the
pulse width by five percent, the value for Ra had to be increased by a large percentage.
This also caused the duty cycle to go above the desired fifty percent level. Ra could not
meet the negative five percent pulse width specification because it would need a value
15
COST ANAYLSIS
Labor
Equipment
16
Vcc
1. Ground
2. Trigger
3. Output
4. Reset Rb
5. Control Voltage
6. Threshold
7. Discharge
8. Vcc
4 8
7
555
3 Ra
6
2 1 5
4-wire 4-wire
DELAY
+ ∑
2 − 2
PHONE wire HYBRID ECHO
wire
ECHOHYBRID
PHONE
CANCEL
CANCEL
DELAY
−
∑∑
+
17
+
Signa Echo +
α z^- ∑
l
d
+ Signa
Error l+
∑
−
+
Adaptiv Estimated − ∑
e Filter
echo
Recovere
d Signal
Fig. 2. System model
18
S ig n a l a n d E c h o
1
0 .5
0
Amp
-0 .5
-1
0 200 400 600 800 1000 1200 1400 1600
T im e s e c
O u tp u t o f S y s te m
1
0 .5
0
Amp
-0 .5
-1
0 200 400 600 800 1000 1200 1400 1600
T im e s e c
L E A R N IN G C U R V E m u = . 0 1 e c h o d e l a y = 6 4 m s r u n s = 2 0 0
0
10
-5
10
E s tim ated M S E , dB
-1 0
10
-1 5
10
400 600 800 1000 1200 1400 1600
N u m b e r o f It e r a t i o n s
F ig . 4 .
19
- - experimental (dashed) -- simulation (solid)
0.06
0.04
0.02
-0.02
-0.04
-0.06
0 2 4 6 8 10 12 14 16 18 20
Fig. 5. Adaptive filter coefficients
20
E x p e r im e n t a l m u = . 3 t a p s = 2 0 d e la y = 6 4 m s
0
-1 0
-2 0
-4 0
-5 0
-6 0
-7 0
0 0 .1 0 .2 0 .3 0 .4 0 .5 0 .6 0 .7 0 .8 0 .9 1
N o r m a l i z e d fr e q u e n c y ( N y q u i s t = = 1 )
200
-2 0 0
P hase (degrees)
-4 0 0
-6 0 0
-8 0 0
-1 0 0 0
0 0 .1 0 .2 0 .3 0 .4 0 .5 0 .6 0 .7 0 .8 0 .9 1
N o r m a l i z e d fr e q u e n c y ( N y q u i s t = = 1 )
21
S im u la t io n m u = . 0 1 t a p s = 2 0 d e la y = 6 4 m s
0
-1 0
-2 0
M agnitude Res pons e (dB )
-3 0
-4 0
-5 0
-6 0
-7 0
0 0 .1 0 .2 0 .3 0 .4 0 .5 0 .6 0 .7 0 .8 0 .9 1
N o r m a l i z e d fr e q u e n c y ( N y q u is t = = 1 )
200
100
P has e (degrees )
-1 0 0
-2 0 0
0 0 .1 0 .2 0 .3 0 .4 0 .5 0 .6 0 .7 0 .8 0 .9 1
N o r m a l i z e d fr e q u e n c y ( N y q u is t = = 1 )
22
TABLE 1. COMPARISON OF THEORECTICAL AND EXPERIMENTAL VLAUES
23
Duty Cycle 49.44 % 37.04 %
24
s=.4*sin(2*pi*freq*t);%Pure Signal
x=noise+s;%input to adaptive filter
echo_amp_per = .4; %Echo percent of signal
%rand('state',sum(100*clock));%Reset Randome Generator
echo_time_delay = .064;
echo_delay=echo_time_delay*samplerate;
echo = echo_amp_per*[zeros(1,echo_delay) x(echo_delay+1:samples)];
%LMS
for i=1:max_iterations;
y(i)=w*x(i:i+taps-1)';
e(run,i)=echo(i)-y(i);
%mule(i) = .5/(x(i:i+taps-1)*x(i:i+taps-1)'+ .01);
w = w + 2*mule*e(run,i)*x(i:i+taps-1);
end
end
%%Mean Square Error
mse=sum(e.^2,1)/max_run;
b=x+echo;
%Ouput of System
out=b(1:length(y))-y;
subplot(3,1,1),plot(b);
title('Signal and Echo');
ylabel('Amp');
xlabel('Time sec');
subplot(3,1,2),plot(out);
title('Output of System');
ylabel('Amp');
xlabel('Time sec');
subplot(3,1,3),semilogy(mse);
grid
title('LEARNING CURVE mu=.01 echo delay=64ms runs=200');
ylabel('Estimated MSE, dB');
xlabel('Number of Iterations');
%subplot(3,1,2),semilogy(iterations,e(1,:).^2);
%grid
%subplot(3,1,3),semilogy(iterations,e(2,:).^2);
%grid
25