Professional Documents
Culture Documents
By
Michael Hutson
ii
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
I declare that the work submitted is my own, except as acknowledged in the text and
footnotes, and has not been previously submitted for a degree at the University of
Queensland or any other institution.
Yours Sincerely,
MICHAEL HUTSON
iii
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
iv
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
ACKNOWLEDGEMENTS.
Thanks go to Dr. Vaughan Clarkson, my thesis supervisor. Without him this work would
never have been completed. His advice, assistance and patience are greatly appreciated.
Also, thank you to my family and friends for tolerating my regular madness during this
project.
v
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
vi
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
TABLE OF CONTENTS.
1. INTRODUCTION. .............................................................................................5
2. BACKGROUND THEORY................................................................................9
3.1 INTRODUCTION..................................................................................................... 17
1
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
7. BIBLIOGRAPHY ............................................................................................57
B.1 nlms_adfilt.c.............................................................................................................. 69
2
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
Thesis Abstract
The signal interference caused by acoustic echo is distracting to both users and causes a
reduction in the quality of the communication. This thesis focuses on the use of adaptive
filtering techniques to reduce this unwanted echo, thus increasing communication quality.
Adaptive filters are a class of filters that iteratively alter their parameters in order to
minimise a function of the difference between a desired target output and their output. In
the case of acoustic echo in telecommunications, the optimal output is an echoed signal
that accurately emulates the unwanted echo signal. This is then used to negate the echo in
the return signal. The better the adaptive filter emulates this echo, the more successful the
cancellation will be.
This thesis examines various techniques and algorithms of adaptive filtering, employing
discrete signal processing in MATLAB. Also a real-time implementation of an adaptive
echo cancellation system has been developed using the Texas Instruments
TMS320C6711 DSP development kit.
3
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
4
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
1. Introduction.
The topic for this thesis is “Acoustic Echo Cancellation using Digital Signal Processing”.
Acoustic echo occurs when an audio signal is reverberated in a real environment,
resulting in the original intended signal plus attenuated, time delayed images of this
signal.
This thesis will focus on the occurrence of acoustic echo in telecommunication systems.
Such a system consists of coupled acoustic input and output devices, both of which are
active concurrently. An example of this is a hands-free telephony system. In this scenario
the system has both an active loudspeaker and microphone input operating
simultaneously. The system then acts as both a receiver and transmitter in full duplex
mode. When a signal is received by the system, it is output through the loudspeaker into
an acoustic environment. This signal is reverberated within the environment and returned
to the system via the microphone input. These reverberated signals contain time delayed
images of the original signal, which are then returned to the original sender (Figure 1.1,
ak is the attenuation, tk is time delay). The occurrence of acoustic echo in speech
transmission causes signal interference and reduced quality of communication.
5
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
The method used to cancel the echo signal is known as adaptive filtering. Adaptive filters
are dynamic filters which iteratively alter their characteristics in order to achieve an
optimal desired output. An adaptive filter algorithmically alters its parameters in order to
minimise a function of the difference between the desired output d(n) and its actual
output y(n). This function is known as the cost function of the adaptive algorithm. Figure
1.2 shows a block diagram of the adaptive echo cancellation system implemented
throughout this thesis. Here the filter H(n) represents the impulse response of the acoustic
environment, W(n) represents the adaptive filter used to cancel the echo signal. The
adaptive filter aims to equate its output y(n) to the desired output d(n) (the signal
reverberated within the acoustic environment). At each iteration the error signal,
e(n)=d(n)-y(n), is fed back into the filter, where the filter characteristics are altered
accordingly.
This thesis deals with acoustic echo as applies to telecommunication systems, although
the techniques will be applicable to a variety of other disciplines.
6
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
7
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
8
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
2. BACKGROUND THEORY
In order to understand the content presented in this thesis it is first necessary to provide
some background information regarding digital signal theory. It will start out rather
elementary and then progress to more complicated matters. Later chapters will build upon
this theoretical basis in the derivation and implementation of the adaptive filtering
techniques used in acoustic echo cancellation.
For example, consider a continuous waveform given by x(t). In order to process this
waveform digitally we first must convert this into a discrete time vector. Each value in
the vector represents the instantaneous value of this waveform at integer multiples of the
sampling period. The values of the sequence, x(t) corresponding to the value at n times
the sampling period is denoted as x(n).
x ( n) = x ( nTs ) (eq 2.1)
9
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
widely used. However, this thesis shall be contained to adaptive filtering using a
particular method known as transversal finite impulse response (FIR) filters.
The utilisation of an FIR filter is simple, the output of the FIR filter at time n is
determined by the sum of the products between the tap weight vector, w(n) and N time
delayed input values. If these time delayed inputs are expressed in vector form by the
column vector x(n) = [x(n) x(n-1) x(n-2) …. x(n-N+1)]T, the output of the filter at time n
is expressed by equation 2.2. Throughout this thesis the vector containing the time
delayed input values at time n is referred to as the input vector, x(n). In adaptive filtering
the tap weight values are time varying so for each at each time interval a new FIR tap
weight vector must be calculated, this is denoted as the column vector w(n) = [w0(n)
w1(n) w2(n) …. wN-1(n)] T.
N −1
y (n) = ∑ wi (n) x (n − i )
i =0 (eq 2.2)
It can be seen that this is also equivalent to the dot product between the impulse response
vector and the input vector, and alternatively the product of the transpose of the filter tap
weight vector and the input vector, see equation 2.3. Both of these equalities will be used
throughout the thesis.
y ( n) = w ( n) ⋅ x(n)
y (n) = w T (n)x(n) (eq 2.3)
10
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
Figure 2.1 shows a block schematic of a real transversal FIR filter, here the input values
are denoted by u(n), the filter order is denoted by M, and z-1 denotes a delay of one
sample period.
Adaptive filters utilise algorithms to iteratively alter the values of the impulse response
vector in order to minimise a value known as the cost function. The cost function, ξ(n), is
a function of the difference between a desired output and the actual output of the FIR
filter. This difference is known as the estimation error of the adaptive filter, e(n) = d(n)-
y(n) . Section 3 will examine adaptive filter theory further and derive several algorithms
used.
A random signal, expressed by random variable function, x(t), does not have a precise
description of its waveform. It may, however, be possible to express these random
processes by statistical or probabilistic models (Diniz 1997, p.17). A single occurrence of
a random variable appears to behave unpredictably. But if we take several occurrences of
11
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
the variable, each denoted by n, then the random signal is expressed by two variables,
x(t,n).
The main characteristic of a random signal treated in this thesis is known as the
expectation of a random signal. It is defined as the mean value across all n occurrences of
that random variable, denoted by E[x(t)], where x(t) is the input random variable. It
should be noted that the number of input occurrences into the acoustic echo cancellation
system is always 1. Throughout this thesis the expectation of an input signal is equal to
the actual value of that signal. However, the E[x(n)] notation shall still be used in order to
derive the various algorithms used in adaptive filtering.
As this thesis deals only with real signals the above equation becomes.
φxx (n, m) = E [ x (n) x (m)] (eq 2.5)
The derivations of adaptive filtering algorithms utilise the autocorrelation matrix, R. For
real signals this is defined as the matrix of expectations of the product of a vector x(n)
and its transpose. This is shown in equation 2.6 (Diniz 1997, p27).
E x (k )2
0 [ ] [
E x0 ( k ) x1 ( k ) ] [ ]
... E x0 ( k ) x N ( k )
[
E x1 ( k ) x0 ( k )
R=
] [
E x1 ( k ) 2 ] [ ]
... E x1 ( k ) x N ( k )
... ... ... ...
[
E x N ( k ) x0 ( k )
] [ E x N ( k ) x1 ( k ) ] ... [
E x N ( k ) 2 ]
R = E [ x( k ) x T ( k ) ] (eq 2.6)
12
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
The autocorrelation matrix has the additional property that its trace, i.e. the sum of its
diagonal elements, is equal to the sum of the powers of the values in the input vector
(Farhang-Boroujeny 1999, p. 97).
As we will see later, sometimes a single value replaces one of the vectors in the
autocorrelation matrix, in this case the correlation function results in a vector. This vector
is given by the expectation of that single value multiplied by the expectation of each of
the values in the vector.
The above implies that the statistical properties of a stationary signal are constant over
time. In the derivation of adaptive filtering algorithms it is often assumed that the signals
input to the algorithm are stationary. Speech signals are not stationary in the wide sense,
however the do exhibit some temporary stationary behaviour as will be seen in the next
section.
13
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7 8 9 10
Sample Number 4
x 10
14
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
assumption of this thesis that the short term stationary behaviour outlined above will
prove adequate for the adaptive filters to function as desired.
If A = B −1 + CD −1C H
then A −1 = B − BC(D + C H BC) −1 C H B (eq 2.9)
A special form of the matrix inversion lemma is used in the derivation of the recursive
least squares (RLS) adaptive filtering algorithm in section 3.4. This special form is stated
in equation 2.10, for an arbitrary non-singular NxN matrix A, any Nx1 vector a, and a
scalar α (Farhang-Boroujeny 1999, p.421).
αA −1aa T A −1
( A + αaa ) = A −
T −1 −1
1 + αa T A −1a (eq 2.10)
15
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
16
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
3. ADAPTIVE FILTERS.
3.1 INTRODUCTION
Figure 3.1 shows the block diagram for the adaptive filter method utilised in this thesis.
The aim of an adaptive filter is to calculate the difference between the desired signal and
the adaptive filter output, e(n). This error signal is fed back into the adaptive filter and its
coefficients are changed algorithmically in order to minimise a function of this
difference, known as the cost function. In the case of acoustic echo cancellation, the
optimal output of the adaptive filter is equal in value to the unwanted echoed signal.
When the adaptive filter output is equal to desired signal the error signal goes to zero. In
this situation the echoed signal would be completely cancelled and the far user would not
hear any of their original speech returned to them.
17
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
This section examines adaptive filters and various algorithms utilised. The various
methods used in this thesis can be divided into two groups based on their cost functions.
The first class are known as Mean Square Error (MSE) adaptive filters, they aim to
minimise a cost function equal to the expectation of the square of the difference between
the desired signal d(n), and the actual output of the adaptive filter y(n) (equation 3.1).
ξ (n) = E [ e 2 (n)] = E [(d (n) − y (n)) 2 ] (eq 3.1)
The second class are known as Recursive Least Squares (RLS) adaptive filters and they
aim to minimise a cost function equal to the weighted sum of the squares of the
difference between the desired and the actual output of the adaptive filter for different
time instances. The cost function is recursive in the sense that unlike the MSE cost
function, weighted previous values of the estimation error are also considered. The cost
function is shown below in equation 3.2, the parameter λ is in the range of 0<λ<1. It is
known as the forgetting factor as for λ<1 it causes the previous values to have an
increasingly negligible effect on updating of the filter tap weights (Diniz 1997, p. 184).
The value of 1/(1- λ ) is a measure of the memory of the algorithm (Farhang-Boroujeny
1999, p. 420), this thesis will primarily deal with infinite memory ,i.e. λ =1. The cost
function for RLS algorithm, ζ(n), is stated in equation..
n
ζ (n) = ∑ ρn ( k )en2 ( k )
k =1
ρn ( k ) = λn − k (eq 3.2)
Where k=1, 2, 3…n., k=1 corresponds to the time at which the RLS algorithm
commences. Later we will see that in practice not all previous values are considered,
rather only the previous N (corresponding to the filter order) error signals are considered.
As stated previously, considering that the number of processes in our ensemble averages
is equal to one, the expectation of an input or output value is equal to that actual value at
a unique time instance. However, for the purposes of deriving these algorithms, the
expectation notation shall still be used.
18
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
Consider the output of the transversal FIR filter as given below, for a filter tap weight
vector, w(n), and input vector, x(n).
N −1
y (n) = ∑ w(n) x (n − i ) =w T (n)x(n)
i =0 (eq 3.3)
The mean square error cost function can be expressed in terms of the cross-correlation
vector between the desired and input signals, p(n)=E[x(n) d(n)], and the autocorrelation
matrix of the input signal, R(n)=E[x(n)xT(n)].
ξ ( n) = E [ e 2 ( n) ]
= E [(d (n) − y (n)) 2 ]
= E [ d 2 ( n) − 2d ( n) w T ( n) x( n) + w T ( n) x( n) x T ( n) w ( n ) ]
= E [ d 2 ( n) ] − 2 E [ w T ( n ) x ( n ) ] + E [ w T ( n) x( n) x T ( n) w ( n) ]
= E [ d 2 (n)] − 2 w T p + w T Rw
(eq 3.4)
When applied to FIR filtering the above cost function is an N-dimensional quadratic
function. The minimum value of ξ(n) can be found by calculating its gradient vector
related to the filter tap weights and equating it to 0.
∂
= 0 for i = 0,1,..., N -1
∂wi
T
∂ ∂ ∂
∇= ...
∂wo ∂w1 ∂wN −1
∇ξ = 0 (eq 3.5)
By finding the gradient of equation 3.4, equating it to zero and rearranging gives us the
optimal wiener solution for the filter tap weights, wo.
19
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
∇ξ = 0
2Rw 0 − 2p = 0
w 0 = R −1p (eq 3.6)
The optimal wiener solution is the set of filter tap weights which reduce the cost function
to zero. This vector can be found as the product of the inverse of the input vector
autocorrelation matrix and the cross correlation vector between the desired signal and the
input vector. The Least Mean Square algorithm of adaptive filtering attempts to find the
optimal wiener solution using estimations based on instantaneous values.
The Least Mean Square (LMS) algorithm was first developed by Widrow and Hoff in
1959 through their studies of pattern recognition (Haykin 1991, p. 67). From there it has
become one of the most widely used algorithms in adaptive filtering. The LMS algorithm
is a type of adaptive filter known as stochastic gradient-based algorithms as it utilises the
gradient vector of the filter tap weights to converge on the optimal wiener solution. It is
well known and widely used due to its computational simplicity. It is this simplicity that
has made it the benchmark against which all other adaptive filtering algorithms are
judged (Haykin 1991, p. 299).
With each iteration of the LMS algorithm, the filter tap weights of the adaptive filter are
updated according to the following formula (Farhang-Boroujeny 1999, p. 141).
w (n + 1) = w (n) + 2 µe(n)x(n) (eq 3.7)
Here x(n) is the input vector of time delayed input values, x(n) = [x(n) x(n-1) x(n-2) ….
x(n-N+1)]T. The vector w(n) = [w0(n) w1(n) w2(n) …. wN-1(n)] T represents the
coefficients of the adaptive FIR filter tap weight vector at time n. The parameter µ is
known as the step size parameter and is a small positive constant. This step size
20
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
parameter controls the influence of the updating factor. Selection of a suitable value for µ
is imperative to the performance of the LMS algorithm, if the value is too small the time
the adaptive filter takes to converge on the optimal solution will be too long; if µ is too
large the adaptive filter becomes unstable and its output diverges.
21
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
= − 2 e( n )
∂w
= − 2 e( n ) x ( n ) (eq 3.10)
Substituting this into the steepest descent algorithm of equation 3.8, we arrive at the
recursion for the LMS adaptive algorithm.
w ( n + 1) = w ( n) + 2 µe( n) x( n) (eq 3.11)
The main reason for the LMS algorithms popularity in adaptive filtering is its
computational simplicity, making it easier to implement than all other commonly used
adaptive algorithms. For each iteration the LMS algorithm requires 2N additions and
2N+1 multiplications (N for calculating the output, y(n), one for 2µe(n) and an additional
N for the scalar by vector multiplication) (Farhang-Boroujeny 1999, p. 141).
22
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
signal prior to commencing the adaptive filtering operation. In practice this is rarely
achievable. Even if we assume the only signal to be input to the adaptive echo
cancellation system is speech, there are still many factors such as signal input power and
amplitude which will affect its performance.
The normalised least mean square algorithm (NLMS) is an extension of the LMS
algorithm which bypasses this issue by selecting a different step size value, µ(n), for
each iteration of the algorithm. This step size is proportional to the inverse of the total
expected energy of the instantaneous values of the coefficients of the input vector x(n)
(Farhang-Boroujeny 1999, p.172). This sum of the expected energies of the input samples
is also equivalent to the dot product of the input vector with itself, and the trace of input
vectors auto-correlation matrix, R (Farhang-Boroujeny 1999, p.173).
N −1
tr[ R ] = ∑ E [ x 2 (n − i )]
i =0
N −1
= E ∑ x 2 (n − i )
i =0 (eq 3.15)
The recursion formula for the NLMS algorithm is stated in equation 3.16.
1
w (n + 1) = w (n) + T e( n ) x ( n )
x ( n) x( n) (eq 3.16)
23
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
Next we minimise (e+(n))2, with respect to µ(n). Using this we can then find a value for
µ(n) which forces e+(n) to zero.
1
µ ( n) = T
2x (n)x(n) (eq 3.18)
This µ(n) is then substituted into the standard LMS recursion replacing µ, resulting in the
following.
w (n + 1) = w (n) + 2 µ (n)e(n)x(n)
1
w (n + 1) = w (n) + T e( n ) x ( n )
x ( n) x( n) (eq 3.19)
Often the NLMS algorithm is expressed as equation 3.20, this is a slight modification of
the standard NLMS algorithm detailed above. Here the value of ψ is a small positive
constant in order to avoid division by zero when the values of the input vector are zero.
This was not implemented in the real time implementation as in practice the input signal
is never allowed to reach zero due to noise from the microphone and from the AD codec
on the Texas Instruments DSK. The parameter µ is a constant step size value used to alter
the convergence rate of the NLMS algorithm, it is within the range of 0<µ<2, usually
being equal to 1. One is the value that has been used throughout the Matlab
implementations and the real time application of sections 4 and 5.
w (n + 1) = w (n) + µ (n)x(n)
µ
where µ (n) =
x x +ψ
T
(eq 3.20)
24
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
As the NLMS is an extension of the standard LMS algorithm, the NLMS algorithms
practical implementation is very similar to that of the LMS algorithm. Each iteration of
the NLMS algorithm requires these steps in the following order (Farhang-Boroujeny
1999, p. 175).
1. The output of the adaptive filter is calculated.
N −1
y (n) = ∑ w(n) x (n − i ) =w T (n)x(n)
i =0 (eq 3.21)
2. An error signal is calculated as the difference between the desired signal and the
filter output.
e( n) = d ( n) − y ( n) (eq 3.22)
4. The filter tap weights are updated in preparation for the next iteration.
w (n + 1) = w (n) + µ (n)e(n)x(n) (eq 3.24)
Each iteration of the NLMS algorithm requires 3N+1 multiplications, this is only N
more than the standard LMS algorithm and as we shall see in section 4.2, this is an
acceptable increase considering the gains in stability and echo attenuation achieved.
25
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
wi (n + 1) = wi + 2 µi gi (n)
g ( n ) = e( n ) x ( n ) (eq 3.25)
Where g is a vector comprised of the gradient terms, gi(n)=e(n)x(n-i), i=0…N-1, the
length corresponds to the order of the adaptive filter. The values for µ(n) can be
calculated in either of the methods expressed in equation 3.26. The choice is dependent
on the application, if a digital signal processor is used then the second equation is
preferred. However, if a custom chip is designed then the first equation is usually utilised
(Farhang-Boroujeny, p.176). For both the Matlab and real time applications the first
equation is being implemented. Here ρ is a small positive constant optionally used to
control the effect of the gradient terms on the update procedure, in the later
implementations this is set to 1.
µi (n) = µi (n − 1) + ρsign( gi (n)) sign( gi (n − 1))
µi (n) = µi (n − 1) + ρgi (n) gi (n − 1) (eq 3.26)
In order to ensure the step size parameters do not become too large (resulting in
instability), or too small (resulting in slow reaction to changes in the desired impulse
response), the allowable values for each element in the step size are bounded by upper
and lower values (Farhang-Boroujeny, p.176). As with the standard LMS algorithm this
implies that a prior knowledge of the signal statistics is necessary to guarantee optimal
performance of the adaptive filter. A method to overcome this requirement is proposed in
the section 3.3.4, ‘Variable Step Size Normalised LMS algorithm’.
26
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
It is a natural progression to incorporate this step size calculation into the variable step
size algorithm, in order increase stability for the filter without prior knowledge of the
input signal statistics. This is what I have tried to achieve in developing the Variable step
size normalised least mean square (VSNLMS) algorithm.
In the VSNLMS algorithm the upper bound available to each element of the step size
vector, µ(n), is calculated for each iteration. As with the NLMS algorithm the step size
value is inversely proportional to the instantaneous input signal energy.
27
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
ρ is an optional constant the same as is the VSLMS algorithm. With ρ =1, each
iteration of the VSNLMS algorithm requires 5N+1 multiplication operations.
28
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
n
ζ (n) = ∑ λn − k en2 ( k )
k =1 (eq 3.33)
Unlike the LMS algorithm and its derivatives, the RLS algorithm directly considers the
values of previous error estimations. RLS algorithms are known for excellent
performance when working in time varying environments…these advantages come with
the cost of an increased computational complexity and some stability problems (Diniz
p.183).
The following derivation of the RLS is summarised from Farhang-Boroujeny pages 419
to 425. First we define yn(k) as the output of the FIR filter, at n, using the current tap
weight vector, and the input vector of a previous time k. The estimation error value en(k)
is the difference between the desired output value at time k, and the corresponding value
of yn(k). These and other appropriate definitions are expressed in equation 3.34, for k=1,
2, 3,…, n.
yn ( k ) = w T ( n ) x ( k )
en ( k ) = d ( k ) − yn ( k )
d(n) = [d (1), d (2)... d (n)]T
y(n) = [ yn (1), yn (2)... yn (n)]T
e(n) = [en (1), en (2)... en (n)]T
e(n) = d(n) − y(n) (eq 3.34)
If we define the X(n) as the matrix consisting of the n previous input column vector up to
the present time then y(n) can also be expressed as equation 3.35.
29
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
We then derive the gradient of the above expression for the cost function with respect to
the filter tap weights. By forcing this to zero we then find the coefficients for the filter,
w(n) , which minimises the cost function.
~ ~
Ψλ (n) w (n) = θλ ( n)
~ ~
w (n) = Ψλ −1 (n)θλ ( n) (eq 3.38)
The matrix Ψ(n) in the above equation can be expanded and then rearranged in a
recursive form, we can then use the special form of the matrix inversion lemma of
equation 2.10 to find an inverse for this matrix, which is required to calculate the tap
30
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
weight vector update. The vector k(n) is known as the gain vector and is included in
order to simplify the calculation.
~ ~
Ψλ−1 (n) = λΨλ−1 (n − 1) + x(n)x T (n)
~ ~
−1 ~ −1 λ− 2 Ψλ−1 (n − 1)x(n)x T (n) Ψλ−1 (n − 1)
= λ Ψλ (n − 1) − ~
1 + λ−1x T ( n) Ψλ−1 (n − 1)x(n)
~ ~
= λ−1 ( Ψλ−1 (n − 1) − k (n)x T (n) Ψλ−1 (n − 1))
~
λ−1Ψλ−1 (n − 1)x(n)
where k (n) = ~
1 + λ−1x T (n) Ψλ−1 (n − 1)x(n)
~
= Ψλ−1 ( n)x(n)
(eq 3.39)
The vector θλ(n) of equation 3.37 can also be expressed in a recursive form. Using this
and substituting Ψ-1(n) from equation 3.39 into equation 3.38 we can finally arrive at the
filter weight update vector for the RLS algorithm, as in equation 3.40.
~ ~
θλ (n) = λθλ (n − 1) + x(n)d(n)
~ ~
w (n) = Ψλ−1 (n)θλ (n)
~ ~ ~ ~
= Ψλ−1 (n − 1)θλ (n − 1) − k (n)x T Ψλ−1 (n − 1)θλ (n − 1) + k (n)d (n)
= w (n − 1) − k (n)x T (n) w (n − 1) + k (n)d (n)
= w (n − 1) + k (n)(d (n) − w T (n − 1)x(n))
w (n) = w (n − 1) + k (n)en −1 (n)
where en −1 (n) = d (n) − w T (n − 1)x(n) (eq 3.40)
To implement the RLS algorithm, the following steps are executed in the following order.
31
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
1. The filter output is calculated using the filter tap weights from the previous
iteration and the current input vector.
yn −1 (n) = w T (n − 1)x(n) (eq 3.41)
Each iteration of the RLS algorithm requires 4N2 multiplication operations and 3N2
additions (Farhang-Boroujeny p. 424). This makes its very costly to implement, thus
LMS based algorithms, while they do not perform as well, are more favourable in
practical situations.
32
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
-1
0 0.5 1 1.5 2 filter output
Adaptive 2.5 3 y(n)
signal, 3.5 4 4.5 5
1 4
x 10
-1
0 0.5 1 1.5 2 2.5error, e(n)3
Estimation 3.5 4 4.5 5
1 4
x 10
-1
0 0.5 1 1.5 2Mean Square
2.5 Error 3 3.5 4 4.5 5
0.01 4
x 10
0.005
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
4
x 10
Figure 4.1: LMS algorithm outputs for vocal input, N=1000, µ=0.007.
33
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
The success of the echo cancellation can be determined by the ratio of the desired signal
and the error signal. Figure 4.2 shows this attenuation as expressed in decibels. The
average attenuation for this simulation of the LMS algorithm is –18.2dB.
0.5
Amplitude
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
4
x 10
Attenuation, (dB)
0
-10
Attenuation
-20
-30
-40
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
4
x 10
Figure 4.3 shows the estimated impulse response of the LMS algorithm at integer
multiples of 7500 iterations. It can be seen that the adaptive filter more accurately
represents the actual impulse response of the simulated echo as the algorithm progresses.
34
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
-7
x 10 Adaptive FIlter Impulse Response, iteration=1
3
0
0 100 200 300 400 500 600 700 800 900 1000
Adaptive FIlter Impulse Response, iteration=7500
0.15
0.1
0.05
-0.05
0 100 200 300 400 500 600 700 800 900 1000
0.2
0.1
-0.1
0 100 200 300 400 500 600 700 800 900 1000
Adaptive FIlter Impulse Response, iteration=22500
0.3
0.2
0.1
-0.1
0 100 200 300 400 500 600 700 800 900 1000
Adaptive FIlter Impulse Response, iteration=30000
0.3
0.2
0.1
-0.1
0 100 200 300 400 500 600 700 800 900 1000
35
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
-1
0 0.5 1 1.5output, y(n)
Adaptive filter 2 2.5 3
1 4
x 10
-1
0 0.5 1 1.5error, e(n)
Estimation 2 2.5 3
1 4
x 10
-1
0 -3 0.5 1 1.5Error (MSE)
Mean Square 2 2.5 3
x 10
1 4
x 10
0.5
0
0 0.5 1 1.5 2 2.5 3
4
x 10
Comparing this with figure 4.1, we can see that the error signal is smaller and the
amplitude of the mean square error is in the order of ten times smaller than that of the
standard LMS algorithm. This comes with the addition of only N more multiplication
operations.
Figure 4.5 shows the dB attenuation of the echoed signal by the NLMS adaptive filter, it
has an average attenuation of –27.9 dB, an approximate improvement of 10 dB over the
standard LMS algorithm. This increase in performance, for marginal computational
36
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
increase, as well as the increase in stability make it perfect for the real time echo
cancellation system outlined in section 5.
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5
4
x 10
Attenuation
0
-10
Attenuation (dB)
-20
-30
-40
0 0.5 1 1.5 2 2.5
4
x 10
The NLMS adaptive filter impulse response after 30000 iterations is shown in figure 4.7.
Comparing this to figure 4.3, the NMLS impulse response has peaks of approximately
twice the amplitude of the LMS algorithm after the same number of iterations, this shows
the convergence rate of the NLMS algorithm is greater than that of the standard LMS
algorithm.
37
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3
4
x 10
Variable Step Size
1
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3
4
x 10
0.5
-0.5
0 100 200 300 400 500 600 700 800 900 1000
0.5
-0.5
0 100 200 300 400 500 600 700 800 900 1000
38
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
-1
0 0.5 1 1.5output, y(n)
Adaptive filter 2 2.5 3
1 4
x 10
-1
0 0.5 1 1.5error, e(n)
Estimation 2 2.5 3
1 4
x 10
-1
0 0.5 1 1.5Error, MSE
Mean Square 2 2.5 3
0.04 4
x 10
0.02
0
0 0.5 1 1.5 2 2.5 3
4
x 10
Figure 4.9 shows the attenuation performance of the VSLMS algorithm, again it shows
the algorithms poor performance. It has an average attenuation of –9.8 dB almost half
that of the standard LMS algorithm.
39
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
Figure 4.10 shows the estimation of the impulse response by the VSLMS adaptive
filtering algorithm, again demonstrating its poor performance for speech echo
cancellation.
Desried signal, d(n)
1
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5
4
x 10
Attentuation
0
-5
Attenuation (dB)
-10
-15
-20
0 0.5 1 1.5 2 2.5
4
x 10
0.8
0.6
0.4
0.2
0
0 100 200 300 400 500 600 700 800 900 1000
0.2
0.1
-0.1
0 100 200 300 400 500 600 700 800 900 1000
40
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
-1
0 0.5 1 1.5output, y(n)
Adaptive filter 2 2.5 3
1 4
x 10
-1
0 0.5 1 1.5error, e(n)
Estimation 2 2.5 3
1 4
x 10
-1
0 0.5 1 1.5Error, MSE
Mean Square 2 2.5 3
0.04 4
x 10
0.02
0
0 0.5 1 1.5 2 2.5 3
4
x 10
Figure 4.12 shows the attenuation of the VSNLMS algorithm, comparing this to figures
4.5 and 4.2 we can see that it, like the VSLMS algorithm, does not perform nearly as well
as the NLMS or standard LMS algorithms. The VSNLMS algorithm has an average
41
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
attenuation of –9.9 dB, this is relatively weak performance for 5N+1 multiplication
operations, thus ruling it out of consideration for the echo cancellation system.
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5
4
x 10
Attentuation
0
-5
Attenuation (dB)
-10
-15
-20
0 0.5 1 1.5 2 2.5
4
x 10
Figure 4.14 shows the RLS adaptive filter echo signal attenuation. It is the greatest out of
all the algorithms with an average attenuation of –34.3 dB. Unfortunately, each iteration
of the RLS algorithm requires 4N2 multiplication operations. Far more than any of the
other algorithms.
42
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
-1
0 0.5 1 RLS adaptive 1.5
filter output, y(n) 2 2.5 3
1 4
x 10
-1
0 0.5 1 1.5 signal, e(n)
Error estimation 2 2.5 3
1 4
x 10
-1
0 -3 0.5 1 1.5error (MSE)
Mean square 2 2.5 3
x 10
1 4
x 10
0.5
0
0 0.5 1 1.5 2 2.5 3
4
x 10
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5
4
x 10
Attenuation, dB
0
-10
Attenuation, dB
-20
-30
-40
-50
0 0.5 1 1.5 2 2.5
4
x 10
43
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
RLS adaptive filter estimation, i=1
1
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
RLS adaptive filter estimation, i=2500
1
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
RLS adaptive filter estimation, i=7500
1
0.5
-0.5
0 100 200 300 400 500 600 700 800 900 1000
RLS adaptive filter estimation, i=10000
1
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
Figure 4.15: Convergence of the RLS adaptive filter to actual impulse response.
44
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
Figure 4.15 shows the impulse response of the RLS adaptive filter at integer multiples of
2500 iterations. Comparing this with figure 4.3 it is clear that the RLS algorithm has a far
greater convergence rate that the LMS algorithm. However, this performance comes at
the cost of computational complexity. As stated above, each iteration requires 4N2
multiplications. For echo cancellation systems the FIR filter order is usually in the
thousands. With at least 4 million multiplications required per sample period the RLS
algorithm is too costly to implement. In practice the LMS based algorithms, although
poorer performers, are preferred.
45
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
46
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
The DSK board is connected to a PC via a parallel port. The PC uses TI code composer
studio to create program files which are then loaded onto the DSK, control over
parameters of the echo cancellation system can also be achieved using the CCS.
47
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
The CCS has inbuilt code optimisation options which rapidly increase the execution
speed of an application without requiring the developer to create or modify assembly
code. By using these optimisation options the echo cancellation system was designed to a
suitable level of performance without needing to code in assembly. If time had permitted,
further optimisation would have been performed at the assembly level.
TI CCS allows the user to produce graphical objects such as sliders using General
Extension Language (GEL) format files. GEL files allow the developer to perform
functions such as variable modification in real time without needing to recompile the
source code.
CCS also has facilities to watch variables for monitoring and debug purposes. Also
variables can be visualised using the CCS graphing function. The echo cancellation
system uses support files that are included with the CCS package. It also utilises support
files from the CD accompanying Chassaing’s ‘DSP applications using C and the
TMS320C6x DSK’.
The real-time acoustic echo cancellation system has been implemented as shown in figure
5.1. A microphone is used to input a voice signal from the user, this is then fed in to the
Texas Instrument TMS320C6711 development board. Here it is sampled by the AD535
48
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
codec at a fixed rate of 8 kHz. The first operation performed by the TMS320C6711 is a
simulation of an echo response of a real acoustic environment. This is achieved by
storing each value of the sampled input in a buffer whose index is incremented with each
sample instance. When the buffer index reaches the end of the array, the index is reset.
The echoed signal is generated by adding the instantaneous sample value and the stored
values in the buffer, this signal is then fed back into the buffer resulting in multiple
echoes. The amount of time delay the echoed signal contains is determined by the length
of the buffer as given in equation 5.1. The buffer length of the echo cancellation system
can be adjusted between 300 and 600, giving a time delay in the range of 37.5 and 75 ms.
A round trip time delay of 75ms emulates the effect of sound reflecting off an object
approximately 12 metres away. This echoed signal is what the adaptive filter attempts to
emulate. The better it does this, the more effective the cancellation will be.
buffer length
td =
sample rate
buffer length
=
8000 (eq 5.1)
The algorithm used on the echo cancellation system is the normalised LMS algorithm
detailed in section 3.4. At each new sample time the input is sampled and input to an
array representing the input vector x(n). The step size value for this iteration of the
NLMS algorithm is then calculated by inverting the dot product of the input vector and
itself. Equation 3.19, shows that a small constant should be included in the denominator
to avoid zero divides, however due to the noise inherent in the microphone input and
DSK board this was found to be an unnecessary calculation.
The output of the adaptive filter is then calculated by the dot product of the input vector
and the current filter tap weight vector. This output is then subtracted from the desired
signal to determine the estimation error value, e(n). This error value, the step size value
and the current FIR tap weight vector are then input to the NLMS algorithm to calculate
the filters tap weight to be used in the next iteration.
Using the CCS graphing function the impulse response emulated by the echo cancellation
system can be viewed, this is shown in figure 5.2 below. As can be seen the system
49
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
emulates the impulse response of the desired signal. Figure 5.2 shows impulse peaks of
decreasing magnitude at integer multiples of 600 samples, corresponding to a delay time
of 75 milliseconds.
Figure 5.2. CCS plot of adaptive filter impulse response, delay =600 samples.
Using a GEL slider the user can then choose to listen to either the echo cancelled output,
the adaptive filter output, the echoed input signal or the clean input signal. Another GEL
slider can be used to vary the length of the echo buffer and hence the time delay of the
echo. The CCS application window including these GEL files can be seen in figure 5.3.
50
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
A copy of the source code used in the echo cancellation system can be found on the CD
accompanying this thesis.
51
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
52
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
53
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
The real time acoustic echo cancellation system was successfully developed with the
NLMS algorithm. The system is capable of cancelling echo with time delays of up to 75
ms, corresponding to reverberation off an object a maximum of 12 metres away. This
proves quite satisfactory in emulating a medium to large size room.
There are many possibilities for further development in this discipline, some of these are
as follows.
• The real time echo cancellation system was implemented successfully using the
TI TMSC6711 DSK. However, this system can only cancel those echoes that fall
within the length of the adaptive FIR filter. The length of this filter is currently at
the maximum allowable without assembler coding. Coding in assembler could
allow for further optimisation and an improvement in the systems performance.
• The echo cancellation system was developed on the DSK board, this has certain
parameters such as sampling rate that are unalterable by the developer. Another
possible way to increase the performance of the echo cancellation system is to use
the C6711 digital signal processor in a custom made circuit which could properly
utilise its full potential.
• This thesis dealt with transversal FIR adaptive filters, this is only one of many
methods of digital filtering. Other techniques such as infinite impulse response
(IIR) or lattice filtering may prove to be more effective in an echo cancellation
application.
• The algorithms studied in this thesis perform best under purely stationary signal
conditions. Strictly speaking speech does not fall into this catergory. Further work
could be done in developing techniques specifically designed for non-stationary
speech signals.
I feel that the goals of this thesis project have been accomplished. Unfortunately, like all
things there is only so far one can progress in a finite amount of time. The field of digital
signal processing and in particular adaptive filtering is vast and further research and
development in this discipline could only lead to an improvement on the methods for
acoustic echo cancellation systems studied in this project.
54
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
55
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
56
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
7. BIBLIOGRAPHY
Bellanger, Maurice G., 2001. Adaptive Digital Filters, 2nd edition. Marcel Dekker Inc.,
New York.
Chassaing, Rulph. 2002, DSP applications using C and theTMS320C6x DSK. John Wiley
and Sons, New York.
Cowan, C.F.N., Grant, P.M. 1985, Adaptive Filters. Prentice-Hall, Inc. New Jersey.
Farhang-Boroujeny, B. 1999, Adaptive Filters, Theory and Applications. John Wiley and
Sons, New York.
Gottfried, Byron. 1996, Programming with C. Schaum’s Outlines, 2nd edition. McGraw-
Hill Book Co., New York.
Hancock, Les., Krieger, Morris., Zamir, Saba.1990, The C primer, 3rd edition. McGraw-
Hill, Inc. New York.
Haykin, Simon. 1991, Adaptive Filter Theory. 2nd Edition. Prentice-Hall Inc., New
Jersey.
57
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
58
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
% Convolve the impulse with the input signal to generate the desired signal
desired_signal = conv(input_signal, impulse);
% initialise adaptive filter impulse and input vector to zero vector of length specified at
command line
filter_current = zeros(filter_size,1);
input_vector = zeros(filter_size, 1);
59
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
input_vector(j)=input_vector(j-1);
end
end
60
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
% initialise variables
filter_current = zeros(filter_size,1);
input_vector = zeros(filter_size, 1);
61
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
for i=1:iterations-100
mse(i)=mean(cost(i:i+100));
i
end
62
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
% generate impulse response of acoustic environment and convolve with input to achieve
desired echo signal
impulse=zeros(filter_size,1);
for (i=1:5)
impulse(((i-1)*filter_size/5)+1)=1/i;
end
desired_signal = conv(input_signal, impulse);
% initialise variables
filter_current = zeros(filter_size,1);
input_vector = zeros(filter_size, 1);
stepsize_curr = zeros(filter_size, 1);
stepsize_prev = zeros(filter_size, 1);
gradient_curr = zeros(filter_size, 1);
gradient_prev = zeros(filter_size,1);
63
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
stepsize_curr(j) = ss_upper;
end
if stepsize_curr(j) < ss_lower
stepsize_curr(j) = ss_lower;
end
end
64
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
% initialise variables
filter_current = zeros(filter_size,1);
input_vector = zeros(filter_size, 1);
stepsize_curr = zeros(filter_size, 1);
stepsize_prev = zeros(filter_size, 1);
gradient_curr = zeros(filter_size, 1);
gradient_prev = zeros(filter_size,1);
65
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
stepsize_curr(j) = ss_upper;
end
if stepsize_curr(j) < ss_lower
stepsize_curr(j) = ss_lower;
end
end
% update filter tap weights
filter_current = filter_current + 2*diag(stepsize_curr)*gradient_curr;
66
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
% Initialise varaibles
filter_prev = zeros(filter_size,1);
input_vector = zeros(filter_size, 1);
psi_inv_prev = eye(filter_size);
intermediate= zeros(filter_size, 1);
gain = zeros(filter_size, 1);
67
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
68
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
B.1 nlms_adfilt.c
// nlms_adfilt.c
// Real time implementation of NLMS algorithm for echo cancellation system.
// Uses TI TMS320C6711 DSK.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
// Defines
#define FILTER_LENGTH 2300
#define ECHO_DELAY 600
#define STEP_SIZE 5e-5
#define SCALE 5000.0
#define GAIN 15
// Declare variables
float input, echoed, af_output, error_signal;
float input_vector[FILTER_LENGTH];
float filter[FILTER_LENGTH];
float echo_buffer[ECHO_DELAY];
float step_size = STEP_SIZE; // fixed step size for standard LMS implementation
float nstep_size;
short output;
short output_type=1;
short delay_param=0;
short i, j, eb_index;
69
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
{
suml += a[j] * b[j];
sumh += a[j+1]*b[j+1];
}
return (suml+sumh);
}
if (output_type==2)
output=(short)(echoed*SCALE*GAIN);
if (output_type==3)
output=(short)(af_output*SCALE*GAIN);
70
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
if (output_type==4)
output=(short)(error_signal*SCALE*GAIN);
B.2 NLMS.gel
// GEL file for nlms control
menuitem "LMS"
71
Michael Hutson 33659143 Acoustic Echo using Digital Signal Processing
delay_param=delays;
}
72