Вы находитесь на странице: 1из 25

ECHO CANCELLATION USING ADAPTIVE FILTERING

By

Thanis Tridhavee

And

Steve Vuco

T.A. Inseop Lee

5/4/99

Project Number 6

1
ABSTRACT

This report discusses the implementation of the least mean-square (LMS)

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

in communication networks to correct for the echoes created by line impedance

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

attempt by two undergraduate seniors to acquire more knowledge in digital signal

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

1. Standard Hardware Project

2.1 Introduction…………………………………………………………... 9

2.2 Design Procedure…………………………………………………….. 9


2.3 Design Details………………………………………………………... 10-11
2.4 Conclusion……………………………………………………………. 11

2. Cost Analysis…………………………………………………………………. 12

3. Figure and Tables

4.1 Figures………………………………………………………………… 13-18


4.2 Tables…………………………………………………………………. 19

4. References……………………………………………………………………. 20

APPENDIX 1. MATLAB Echo Cancellation Code……………… 21


APPENDIX 2. Assembly Echo Cancellation Code………………. 22

3
iii
1.1 Introduction

A significant problem in communications is the generation of echoes. The echoes

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

1. (All figures/tables appear at the end of the report.)

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

transmission lines [3].

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

of coefficients. Simulations of the LMS algorithm will be done in MATLAB to get

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.

1.2 Design Procedure

A sinusoid wave is be used as the test signal in simulation and in experiments.

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.

0<µ <2/(total input power) (1)

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,

which is equal to half of the Nyquist rate.

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

commonly used algorithm because it is powerful enough to accomplish the system’s

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

DSPs available today [1].

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:

w(n+1) = w(n)+µ *e(n)*x(n) (3)

(a) w(n) are the present filter coefficients,

(b)w(n+1) are the future adaptive filter coefficients

(c) x(n) are the input values

(d) e(n) is the error value.

(e) µ is the step size

µ determines the convergence or divergence speed and precision of the adaptive

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

adjusted. When choosing a µ value, their needs to be balance between speed

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

differences between the systems.

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).

Output of adaptive filter:

y(n) = ∑ wT(k) * x(n-k) (4)

Sum over k from 0 to N-1 where N = 20

The error signal e(n) is created from the subtraction of the desired signal from the

output of the adaptive filter.

Error Signal:

e(n) = d(n) – y(n) (5)

The output of the echo filter is

Desired Signal = Echo Signal:

d(n) = α *x(n-β ) (6)

β is the delay in samples and α is the attenuation constant.

Then d(n) is added to x(n) to create the distorted signal.

Echo and Input Signal:

7
f(n) = d(n)+x(n) (7)

= α *x(n-β ) + x(n)

Next the reconstructed signal χ (n) is formed by

Reconstructed Signal:

χ (n) = f(n)-y(n) = d(n) +x(n) – y(n) (8)

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

original input signal to update the LMS adaptive filter.

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

model is shown in Figure 2.

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

corresponds to sixty-four milliseconds delay at our sampling rate with an attenuated of

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

than 50 milliseconds [3].

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

coefficients in Figure 5 show similar shapes.

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

simulate the noise that occurs in real systems.

1.4 Design Verification

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

cancellation. The system worked in simulation and in real-time. Adjustments of the µ

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

adaptive filter length are chosen properly.

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

variances of the chosen frequency and pulse width.

2.2 Design Procedure

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

the Motorola source [6].

Charge time (time high):

th = 0.695 (Ra+Rb) C (9)

Discharge time (time low):

tl = 0.695 (Rb) C (10)

13
Period:

T = th + tl = 0.695 (Ra+2Rb) C (11)

Frequency:

F = 1/T = 1.44/((Ra+Rb) C) (12)

Duty Cycle:

DC = Rb/(Ra+2Rb) (13)

Ra minimum:

Ra≥ Vcc/.2 (14)

2.3 Design Details

The standard Ra and Rb values were found to meet the design constraints. The

following values were chosen:

Capacitor = 0.01 µ F

Frequency = 3700 Hz

Pulse width = 100 µ s

Duty Cycle = < 50%

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

so that the duty cycle is less than fifty percent.

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

determine by trial and error.

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

less than Ra minimum.

15
COST ANAYLSIS

Labor

Salary hr = $20 per hr

2 Persons at 220 hrs each

Total Hrs = 220 x 2 = 440 hrs

Total Labor Cost = 20 x 440 x 2.5 = $22,000

Equipment

DSP Chip = $100

DSP EVAL Board = $120

MATLAB = Provide in lab

Circuit Components = $2.00

Total Equipment Cost = $222

Total Cost = $22,222

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

Fig. 6. Clock timer circuit

4-wire 4-wire
DELAY
+ ∑

2 − 2
PHONE wire HYBRID ECHO
wire
ECHOHYBRID
PHONE

CANCEL
CANCEL

DELAY

∑∑
+

Fig. 1. Schematic of telephone system

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

M agnitude Res ponse (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 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

Component Theory Experimental


Ra 146.2 Ω 146.2 Ω
Rb 6.45 kΩ 6.45 kΩ
C .01 µ F 01 µ F
F 11034 Hz 3700 Hz
th 45.87 µ s 100 µ s
tl 44.83 µ s 170 µ s
T 90.7 µ s 270 µ s
Ra minimum 28.3 Ω 116.7 Ω

23
Duty Cycle 49.44 % 37.04 %

TABLE 2. EXPERIMENTAL RESULTS

Ra (Ω ) Rb (kΩ ) Pw (µ s) T (ms) F (Hz) DC Specification


standard 146.2 6.45 100 270.3 3700 37.0% All met
vary Rb 146.3 6.71 105 281.5 3552 37.3% Pw+5%
vary Rb 146.3 6.18 95 254.8 3925 37.3% Pw-5%
vary Rb 146.3 6.28 97 262.4 3811 37.0% F+3%
vary Rb 146.3 6.58 103 279 3584 36.9% F-3%
vary Ra 347.3 6.45 105 209.5 4773 50.1% Pw+5%
vary Ra 116.3 6.45 99 805.2 1242 12.3% Pw min.*
vary Ra 148.2 6.45 100 262.4 3811 38.1% F+3%
vary Ra 142.8 6.45 100 281.5 3552 35.5% F-3%

* Note Pw –5% could not be reached, because values lower than Ra

minimum caused an internal transistor to saturate.

APPENDIX 1. MATLAB ECHO CANCELLATION CODE


clear all;
mule = .01; % Larger values for fast conv
max_run = 200;
for run=1:max_run;
taps = 20; %Adaptive Filter Taps #
freq = 2000;%Signal Freq
w = zeros(1,taps);%state of adaptive filter
time = .2;%lenght of simulation (sec)
samplerate = 8000;%samples/sec
samples = time*samplerate;
max_iterations = samples-taps+1;
iterations = 1:max_iterations;%Vector of iterations
t=1/samplerate:1/samplerate:time;
rand('state',sum(100*clock));%Reset Randome Generator
noise=.02*rand(1,samples);%noise added to signal

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

Вам также может понравиться