Implementation of An Acoustic Echo Canceller Using Matlab
Implementation of An Acoustic Echo Canceller Using Matlab
USF Tampa Graduate Theses and Dissertations USF Graduate Theses and Dissertations
10-15-2003
This Thesis is brought to you for free and open access by the USF Graduate Theses and Dissertations at Digital
Commons @ University of South Florida. It has been accepted for inclusion in USF Tampa Graduate Theses and
Dissertations by an authorized administrator of Digital Commons @ University of South Florida. For more
information, please contact digitalcommons@usf.edu.
Implementation of an Acoustic Echo Canceller
Using Matlab
by
Srinivasaprasath Raghavendran
Date of Approval:
October 15, 2003
A. Moreno, for being a constant source of help and inspiration throughout my work. His
timely advice and guidelines have assisted me to get through a lot of difficult situations.
My other committee members, Dr. James T. Leffew and Dr. Wei Qian have been very
considerate and cooperative with me. I would like to thank them for their prompt
feedback and being approachable and available whenever I needed any assistance. I
would also like to thank the IEC forum for the help and valuable suggestions.
At this juncture, I thank my parents, my sister and my friends for their total
support and encouragement. This Master’s thesis would not have been possible without
their support.
TABLE OF CONTENTS
LIST OF FIGURES iv
ABSTRACT vi
CHAPTER 1 INTRODUCTION 1
1.1 Need for Echo Cancellation 1
1.2 Basics of Echo 2
1.3 Types of Echo 3
1.4 The Process of Echo Cancellation 3
1.4.1 Adaptive Filter 4
1.4.2 Doubletalk Detector 5
1.4.3 Nonlinear Processor 5
1.5 Echo Cancellation Challenges 5
1.5.1 Avoiding Divergence 6
1.5.2 Handling Doubletalk 6
1.5.3 Preventing Clipping 7
1.6 Research Motivation and Thesis Outline 7
i
3.4 Doubletalk Detector (DTD) 31
3.4.1 The Generic Doubletalk Detection Schemes 33
3.4.2 The Geigel Algorithm 34
3.4.3 Cross Correlation Method 35
3.4.4 Normalized Cross Correlation Method 36
3.5 Nonlinear Processor (NLP) 37
3.5.1 Noise Gate as NLP 38
3.5.2 A Generic Expander 38
3.5.3 Noise Gate 40
REFERENCES 57
ii
LIST OF TABLES
iii
LIST OF FIGURES
Figure 2.5: Echo Canceller at Modem Locations for Full-Duplex Voice-band Modems 16
Figure 3.3: Echo Canceller with Doubletalk Detector and Nonlinear Processor 24
iv
Figure 4.3: Plot of the Echo Signal, r(n) 48
v
IMPLEMENTATION OF AN ACOUSTIC ECHO CANCELLER
USING MATLAB
Srinivasaprasath Raghavendran
ABSTRACT
The rapid growth of technology in recent decades has changed the whole dimension of
such a situation, the use a regular loudspeaker and a high-gain microphone, in place of a
telephone receiver, might seem more appropriate. This would allow more than one
environment. Another advantage is that it would allow the person to have both hands
free and to move freely in the room. However, the presence of a large acoustic coupling
between the loudspeaker and microphone would produce a loud echo that would make
conversation difficult. Furthermore, the acoustic system could become instable, which
The solution to these problems is the elimination of the echo with an echo
suppression or echo cancellation algorithm. The echo suppressor offers a simple but
effective method to counter the echo problem. However, the echo suppressor possesses a
communication permits only one speaker to talk at a time. This drawback led to the
vi
invention of echo cancellers. An important aspect of echo cancellers is that full-duplex
communication can be maintained, which allows both speakers to talk at the same time.
algorithm, which is capable of providing convincing results. The three basic components
processor. The adaptive filter creates a replica of the echo and subtracts it from the
combination of the actual echo and the near-end signal. The doubletalk detector senses
the doubletalk. Doubletalk occurs when both ends are talking, which stops the adaptive
filter in order to avoid divergence. Finally, the nonlinear processor removes the residual
echo from the error signal. Usually, a certain amount of speech is clipped in the final
stage of nonlinear processing. In order to avoid clipping, a noise gate was used as a
nonlinear processor in this research. The noise gate allowed a threshold value to be set
and all signals below the threshold were removed. This action ensured that only residual
echoes were removed in the final stage. To date, the real time implementation of echo an
cancellation algorithm was performed by utilizing both a VLSI processor and a DSP
processor. Since there has been a revolution in the field of personal computers, in recent
years, this research attempted to implement the acoustic echo canceller algorithm on a
vii
CHAPTER 1
INTRODUCTION
essential communications tools and have a direct impact on people’s day-to-day personal
becoming ever more critical of the service and voice quality they receive from network
providers. Subscriber demand for enhanced voice quality over wireless networks has
driven a new and key technology termed echo cancellation, which can provide near wire
Today’s subscribers use speech quality as a standard for assessing the overall
it is the key to maintaining subscriber loyalty. For this reason, the effective removal of
hybrid and acoustic echoes, which are inherent within the telecommunications network
infrastructure, is the key to maintaining and improving the perceived voice quality of a
call. Ultimately, the search for improved voice quality has led to intensive research into
the area of echo cancellation. Such research is conducted with the aim of providing
solutions that can reduce background noise and remove hybrid and acoustic echoes
1
before any transcoder processing occurs. By employing echo cancellation technology,
the quality of speech can be improved significantly. This chapter discusses the overall
echo problem. A definition of echo precedes the discussion of the fundamentals of echo
or electrical signal is reflected back to the source. With rare exceptions, conversations
take place in the presence of echoes. Echoes of our speech are heard as they are reflected
from the floor, walls and other neighboring objects. If a reflected wave arrives after a
However, when the leading edge of the reflected wave arrives a few tens of milliseconds
mismatches at various points along the transmission medium. The most important factor
in echoes is called end-to-end delay, which is also known as latency. Latency is the time
between the generation of the sound at one end of the call and its reception at the other
end. Round trip delay, which is the time taken to reflect an echo, is approximately twice
Echoes become annoying when the round trip delay exceeds 30 ms. Such an echo
is typically heard as a hollow sound. Echoes must be loud enough to be heard. Those
less than thirty (30) decibels (dB) are unlikely to be noticed. However, when round trip
2
delay exceeds 30 ms and echo strength exceeds 30 dB, echoes become steadily more
disruptive. However, not all echoes reduce voice quality. In order for telephone
conversations to sound natural, callers must be able to hear themselves speaking. For this
reason, a short instantaneous echo, termed side tone, is deliberately inserted. The side
tone is coupled with the caller’s speech from the telephone mouthpiece to the earpiece so
In telecommunications networks there are two types of echo. One source for an
echo is electrical and the other echo source is acoustic [1]. The electrical echo is due to
(PSTN), exchange where the subscriber two-wire lines are connected to four-wire lines.
If a communication is simply between two fixed telephones, then only the electrical echo
another kind of echo known as an acoustic echo. The acoustic echo is due to the coupling
between the loudspeaker and microphone. These electrical and acoustic echoes are
An echo canceller is basically a device that detects and removes the echo of the
signal from the far end after it has echoed on the local end’s equipment. In the case of
circuit switched long distance networks, echo cancellers reside in the metropolitan
3
Central Offices that connect to the long distance network. These echo cancellers remove
• Adaptive filter
• Doubletalk detector
• Non-linear processor
Doubletalk
Filtered signal Clear signal e(n)
Doubletalk decision Non-Linear
Adaptive Filter
detector Processor
Reference signal
y(n)
The adaptive filter is made up of an echo estimator and a subtractor. The echo
estimator monitors the received path and dynamically builds a mathematical model of the
line that creates the returning echo. The model of the line is convolved with the voice
stream on the receive path. This yields an estimate of the echo, which is applied to the
4
subtractor. The subtractor eliminates the linear part of the echo from the line in the send
path. The echo canceller is said to converge on the echo as an estimate of the line is built
A doubletalk detector is used with an echo canceller to sense when far-end speech
adaptation of the model filter when near-end speech is present. This action prevents
The non-linear processor evaluates the residual echo, which is nothing but the
amount of echo left over after the signal has passed through the adaptive filter. The
nonlinear processor removes all signals below a certain threshold and replaces them with
simulated background noise which sounds like the original background noise without the
echo.
5
1.5.1 Avoiding Divergence
The process of divergence is an adaptive filter problem that arises when a suitable
solution for the line model is not found through the use of a mathematical algorithm.
Under specific conditions, certain algorithms are bound to diverge and corrupt the signal
or even add echo to the line. Good echo cancellers are tuned to avoid divergence
In an active conversation, both talkers often speak at the same time or interrupt
each other. Those situations are called “doubletalk”. Doubletalk presents a special
follows:
1. A speaks. The echo canceller must compare the received speech from
an echo point.
echo canceller must detect the doubletalk and cancel the echo without
3. The echo canceller must send B’s speech, as well as the echo-cancelled
6
• It must detect doubletalk and distinguish it from background noise.
• The echo canceller must be capable of choosing not to update the line
erroneously removed. Clipping results due to the lack of a precise Non-Linear Processor,
(NLP). Specifically, the NLP fails to start and stop at the right time. Typically, an NLP
does not respond rapidly enough to the introduction of speech through the local end. It
replaces parts of words with background noise, which makes the conversation hard to
follow. The same can happen when the NLP confuses the fading of the voice level at the
has only been possible through the use of custom very large scale integration, (VLSI),
processors or digital signal processors (DSP). These processors are specially designed
for signal processing tasks. They provide parallel processing of commands and
optimized pipeline structures. However, since the computation power of regular home
7
personal computers, (PCs), has increased tremendously and powerful software has
as well. The advent of this growing capability was the motivation for this research. The
objective of the research was the implementation of a software echo canceller running
using a noise gate for the NLP. Chapter 1 discusses the definition of echo, the necessity
of echo cancellers in telecommunications network, the basics of echo cancellation and the
challenges of echo cancellation. Chapter 2 gives an overview of the types of echo and
their sources. It also discusses, in great detail, the echo phenomena in four major
details of the simulation environment and the results obtained. Finally Chapter 5
provides a summary and some ideas concerning further work in this field.
8
CHAPTER 2
This chapter deals with echoes that are generated in telecommunication systems.
As discussed in chapter one, there are two main types of echo, which are termed
Hybrid echoes have been inherent within the telecommunications networks since
the advent of the telephone. This echo is the result of impedance mismatches in the
analog local loop. For example, this happens when mixed gauges of wires are used, or
where there are unused taps and loading coils. In the Public Switched Telephone
Network, (PSTN), by far the main source of electrical echo is the hybrid. This hybrid is a
transformer located at a juncture that connects the two-wire local loop coming from a
subscriber’s premise to the four-wire trunk at the local telephone exchange. The four-
wire trunks connect the local exchange to the long distance exchange. This situation is
9
Hybrid
Echo
4W Trans Port
Hybrid Balance
2W Port Deivce Network
4W Recv Port
The hybrid splits the two-wire local loop into two separate pairs of wires. One
pair is used for the transmission path and the other for the receiver path. The hybrid
passes on most of the signal. However, the impedance mismatch between the two-wire
loop and the four-wire facility causes a small part of the received signal to “leak” back
onto the transmission path. The speaker hears an echo because the far-end receives the
signal and sends part of it back again. Electrical echo is definitely not a problem on local
calls since the relatively short distances do not produce significant delays. However, the
In the early years, when the public network was entirely circuit switched, the
hybrid echo was the only significant source of echo. Since the locations of hybrids and
most other causes of impedance differences in circuit switched networks were known,
adequate echo control could be planned and provisioned. However, in today’s digital
networks the points where two wires split into four wires is typically also the point where
analog to digital conversion takes place. Regardless of whether the hybrid and analog to
10
digital conversion is implemented in the same device or in two devices, the two to four
wire conversions constitute an impedance mismatch and echoes are produced [1].
poor voice coupling between the earpiece and microphone in handsets and hands-free
encoding/decoding devices process the voice paths within the handsets and in wireless
networks. This results in returned echo signals with highly variable properties. When
compounded with inherent digital transmission delays, call quality is greatly diminished
Acoustic coupling is due to the reflection of the loudspeaker’s sound waves from
walls, door, ceiling, windows and other objects back to the microphone. The result of the
reflections is the creation of a multipath echo and multiple harmonics of echoes, which
are transmitted back to the far-end and are heard by the talker as an echo unless
eliminated. Adaptive cancellation of such acoustic echoes has become very important in
11
Loudspeaker
Reflections
Direct
coupling
Microphone
• Teleconference/videoconference systems
connection contains two-wire sections at the ends, the subscriber loops and possibly some
portion of the local network. It also contains a four-wire section in the center, which is a
12
Figure 2.3: Simplified Long Distance Connections
local PSTN exchange by a two-wire line, called the subscriber loop, which carries a
connection for both directions of transmission. Simply connecting the two subscriber
loops at the local exchange sets up a local call. However, amplification of the speech
signal becomes necessary when the distance between the two telephones exceeds 35
miles. Therefore, a four-wire line is required, which segregates the two directions of
transmission. A hybrid is used to convert from the two-wire to four-wire line and vice
versa.
An echo can be decreased if the hybrid has a significant loss between its two four-
wire ports. To achieve this large loss the hybrid has to be perfectly balanced by
impedance located at its four-wire portion. Unfortunately, this is not possible in practice
since it requires knowledge of the two-wire impedance, which varies considerably over
the population of subscriber loops. When the bridge is not perfectly balanced, impedance
mismatch occurs. This causes some of the talker’s signal energy to be reflected back as
an echo. Adding an insertion loss to the four-wire portions of the connection can control
the effects of echo. Such action is effective since the echo signals experience this loss
two or three times while the talker’s speech suffers this loss only once. However, on
long-range connections the insertion loss can become very significant. Hence, it is not a
13
favorable solution and other echo control techniques such as echo suppression must be
used [1].
Echo suppressors have been used since the introduction of long distance
communication. This device basically takes advantage of the fact that people seldom talk
talking”. The echo suppressor is also helped by the fact that during such double talking
poor transmission quality is less noticeable. Figure 2.4 illustrates how the echo
suppressor dynamically controls the connection based on who is talking, which is decided
by the speech and double talking detector. Double talking is detected if the level of the
signal in path L1 is significantly lower than that in path L2. When the far-end talker A is
speaking, the path used to transmit the near-end speech is opened so that the echo is
prevented. Then, when the near-end talker B speaks, the same switch is closed and a
symmetric one at the far-end talker A’s path is opened. However, echo suppressors can
clip speech sounds and introduce impairing interruption. For example, if talker B is
initially listening to talker A but suddenly wants to talk, it is quite likely that the switch
preventing talker A’s echo from being transmitted will not close quickly enough. This
will cause the far-end talker A to not be able to receive all the messages from the near-
end talker B. This deletion is noticed by talker A, encouraging him/her to stop and wait
for talker B to finish. The resulting confusion may stop the conversation entirely while
each party waits for the other to say something [1]. Therefore the best solution for
removing echoes is to use echo cancellers. Echo cancellers are described in chapter 3.
14
Arriving from Far-end
L1
Echo
Doubletalk detector to
Speech
overdrive echo Hybrid
Detector
suppessor
Near-end
Talker B
Echo
Suppessor
L2
Destined for
Far-end
Talker B Signal
The two-wire telephone line of a subscriber loop can be used for the transmission
of data through a modem. This can be accomplished either by using the entire bandwidth
of the wire or transmitting the data on a bandwidth that is slightly above the one used to
carry the speech signal. On an analog subscriber loop the speech signal occupies the
bandwidth between 300 to 3400 Hz. A higher bit rate of up to 16 kbps can be transmitted
by modulating the data signal onto a carrier signal at a band above 4000 Hz. Echo
cancellation is needed for full-duplex communication within the same bandwidth over the
subscriber loop as shown in Figure 2.5 where EC is the echo canceller, H is the hybrid,
15
Figure 2.5: Echo Cancellers at Modem Locations for Full-Duplex Voice-band Modems
Typically the echo cancellers must be placed at the line interface where the
hybrids connect the modem to the two-wire subscriber loop. Several problems are
associated with this type of application and some of them are given below.
• The far-end echo, which is returned from the far-end hybrid, must also be taken
into account. Therefore, the entire echo delay becomes very large, which is
unique to the echo cancellation at the station, or modem, location. If the circuit
includes a satellite communication network’s four-wire link, the far-end echo will
be delayed for more than 500ms. In such a case two cancellers will be required.
One for the near-end and one for the far-end echo at the modems.
near-end echo, which is returned from the first hybrid at the local station, can be
16
40 to 50dB higher than the desired signal. For reliable communication the echo
maintain the signal power approximately 10dB above the echo [2].
coding and signal processing involves considerable delays. In most cases, the delays are
increased further by time division multiple access framing. The total one-way delay can
be from 30 to 120 msec. Figure 2.6 illustrates that only one echo canceller, (EC), facing
the local PSTN exchange, (LE), is required in a digital cellular to fixed telephone
perfect four-wire fashion with no significant acoustic cross talk echo between the
microphone and the earpiece of the cellular phone. However, under certain conditions,
the cross talk echo in cellular handsets is still noticeable by users. Hence, the echo needs
17
Figure 2.6: Cellular to Fixed Telephone Connection
conference rooms, then an acoustic echo problem emerges that is due to the reflection of
the loudspeaker’s sound waves from the boundary surfaces and other objects back to the
microphone. This acoustic echo can be removed using an adaptive filter as illustrated in
Figure 2.7. The adaptive filter attempts to synthesize a model of the acoustic echo at its
output.
18
Enclosed Environment
E.G., A Room or Vehicle
Loudspeaker
From Far-end
x(n)
Talker
Adaptive
Filter r(t)
ŷ(n)
To Far-end Talker
e(n) y(n) Near-end Talker
Σ
Microphone v(n)
• The impulse response of the acoustic echo path is several times longer,
between 100 to 500 msec. than that of the network echo path.
• The characteristics of the acoustic echo path are more non-stationary due to
opening and closing of a door or movement of people inside the room while
• The acoustic echo path has a mixture of linear and nonlinear characteristics.
this nonlinearity are the suspension nonlinearity that affects distortion at low
19
frequency and the inhomogeneity of flux density that produces nonlinear
Due to the above mentioned reasons, the acoustic echo cancellers, (AECs), are
required to have more computing power in order to compensate for the longer impulse
20
CHAPTER 3
This chapter discusses the echo cancellation algorithm for a VoIP environment.
The basic idea behind the algorithm, its terminology, modes of operation and the
in Figure 3.1.
Far-end Talker
x(n)
ŷ( n ) r(n)
_
e(n) d(n) = r(n) + v(n) + + v(n)
Σ Σ
+
Near-end
Talker
synthesize a replica of the echo. Then the echo canceller subtracts the synthesized replica
from the combined echo and near-end speech or disturbance signal to obtain the near-end
identified. This problem can be solved by using an adaptive filter that gradually matches
its estimated impulse response, ĥ , to that of the impulse response of the actual echo path,
h. This process is illustrated in Figure 3.2. The echo path is highly variable and can even
depend on such things as the movement of people in the room as well as other things.
These variations are accounted for by the adaptive control loop, which is built into the
canceller.
Far-end Talker
x(n)
ŷ( n ) r(n)
_
e(n) d(n) = r(n) + v(n) + + v(n)
Σ Σ
+
Near-end
Talker
22
The estimated echo, ŷ(n ) , is generated by passing the reference input signal, x(n),
through the adaptive filter, ĥ (n ) , that will ideally match the transfer function of the echo
path, h(n). The echo signal, r(n), is produced when x(n) passes through the echo path.
The echo r(n) plus the near-end talker or disturbance signal, v(n), constitute the desired
response,
for the adaptive canceller. The two signals x(n) and r(n) are correlated since the later is
obtained by passing x(n) through the echo path. The error signal e(n) is given by
In the ideal case, e(n) = v(n), which represents the case when the adaptive echo canceller
is perfect.
Similar to the echo suppressors, adaptive echo cancellers also face the problem of
double talking when both near and far end speakers talk simultaneously. If double talk
occurs, the system may try to adjust the adaptive filter parameters to imperfectly cancel
the near-end talker signal. This will result in making large corrections to the estimated
echo path, ĥ , in an attempt to mimic h. In order to avoid this possibility the coefficients
in the adaptive filter must not be updated as soon as double talking is detected as
illustrated in Figure 3.3. The design of a good double talking detector is difficult. Even
occurring in the echo channel during the time that the echo canceller is not updated,
double talking is usually short. In addition to these problems, it sometimes occurs that a
well-working echo canceller leaves some residual uncancelled echo. In such a case, a
23
nonlinear processor is used to remove the residual echo. The goal of the nonlinear
processor is to block this small unwanted signal if the signal magnitude is lower than a
certain small threshold value during single talking. The nonlinear processor will only
distort and not block the near-end signal during double talking. The distortion is
generally unnoticeable and the processor does not have to be removed during double
talking [2].
Far-end Talker
x(n)
Open
during
double talk
ŷ (n ) r(n)
Doubletalk
Detector
_
+ + v(n)
Nonlinear
Processor
Σ Σ
+ d(n) = r(n) + v(n) Near-end
e(n)
Talker
Figure 3.3: Echo Canceller with Doubletalk Detector and Nonlinear Processor
The previous section attempted to give some valuable first hand knowledge on the
functioning of a basic echo canceller. The following sections offer a detailed theoretical
24
and mathematical account of the three fundamental components of echo cancellers. The
1. Adaptive Filter
2. Doubletalk Detector
3. Nonlinear Processor
As previously demonstrated, the best solution for reducing the echo is to use some
form of adaptive algorithm. The theory behind such an algorithm and the reasons for
choosing that algorithm will be described in this section. Basically filtering is a signal
information contained in the signal. In other words, a filter is a device that maps its input
signal into another output signal by extracting only the desired information contained in
the input signal. An adaptive filter is necessary when either the fixed specifications are
adaptive filter is a nonlinear filter since its characteristics are dependent on the input
signal and consequently the homogeneity and additivity conditions are not satisfied.
Additionally, adaptive filters are time varying since their parameters are continually
25
3.3.1 Least Mean Square (LMS) Algorithm
The least mean square, (LMS), is a search algorithm that is widely used in various
applications of adaptive filtering. The main features that attracted the use of the LMS
environments and stable behavior when implemented with finite precision arithmetic.
Figure 3.4 illustrates how such an algorithm works. A path that changes the signal x is
called h. Transfer function of this filter is not known in the beginning. The task of the
LMS algorithm is to estimate the transfer function of the filter. The result of the signal
distortion is calculated by convolution and is denoted by r. In this case r is the echo and
h is the transfer function of the hybrid. The near-end speech signal v is added to the echo.
The adaptive algorithm tries to create a filter w. The transfer function of the filter is an
estimate of the transfer function for the hybrid. This transfer function in turn is used for
w h
r̂ r
+ v
Σ
+
_ d= v+r
Σ
+
d − r̂ = v + r − r̂ = v + e
26
The signals are added so that the output signal from the algorithm is
v + r – r̂ = v + e, (3.3)
where e denotes the error signal. The error signal and the input signal x are used for
estimation of the filter coefficient vector w. One of the main problems associated with
choosing the filter weight is that the path h is not stationary. Therefore, the filter weights
must be updated frequently so that the adjustment to the variations can be performed.
However, in a real-time environment, linearity is never a possibility and the first criterion
is not fulfilled so the filter can never be perfect. Updating of the filter weights is realized
in accordance with
for k = 0,1,2,··· where gw(k) represents an estimate of the gradient vector and µ is the
x w + e
ŷ _ Σ
∆w
LMS
where w(k) is a vector containing the filter weights [b0, b1, b2, ···, b0] and x(k) represents
the vector [x(n), x(n-1), ···, x(n-L)]T. L is the length of the adaptive filter.
wo = R-1 p (3.7)
where
and
assuming d(k) and x(k) are jointly wide sense stationary. If good estimates of the matrix
and
28
gw(k ) = 2d(k )x(k) + 2x(k)xT(k)w(k)
= 2x(k)(d(k) + xT(k)w(k))
= 2e(k)x(k). (3.13)
The resulting gradient-based algorithm is known. It minimizes the mean of the squared
error, as the least-mean square (LMS) algorithm, whose updating equation is given by
Table 3.1 presents the steps associated with the LMS algorithm in tabular form.
There are a number of algorithms for adaptive filters, which are derived from the
instantaneous error. Such a convergence factor usually reduces the convergence time but
29
The updating equation of the LMS algorithm can employ a variable convergence
factor µk in order to improve the convergence rate. In this case, the updating formula is
expressed as
1
µk = . (3.16)
2x̂ (k ) x (k )
Using the variable convergence factor the updating equation for the NLMS algorithm is
given by
e( k ) x ( k )
w(k+1) = w (k ) + . (3.17)
x T (k ) x (k )
order to control the misadjustment since all the derivations are based on instantaneous
values of the squared errors and not on the MSE. Also a parameter γ should be included
in order to avoid large steps when xT(k)x(k) becomes small. Then the coefficient updating
is by
2µ n
w(k+1) = w (k ) + e(k ) x (k ) (3.18)
γ + x T (k ) x (k )
30
Table 3.2 presents the steps associated with the NLMS algorithm in tabular form.
2µ n
Tap-Weight Adaptation: w(k+1) = w (k ) + e(k ) x (k )
γ + x T (k ) x (k )
double talk. The condition where both ends, the near-end and the far-end, are speaking is
referred to as double talk. If the echo canceller does not detect a double talk condition
properly the near end speech will cause the adaptive filter to diverge. Therefore, it is
A DTD is used with an echo canceller to sense when the far-end speech is
corrupted by the near-end speech. The role of this important function is to freeze
adaptation of the model filter, ĥ , when the near-end speech, v, is present in order to avoid
divergence of the adaptive algorithm. The far-end talker signal, x, is filtered with the
impulse response, h, and the resulting signal. The echo is added to the near-end speech
31
d(n) = HTx(n) + v(n) (3.19)
where
and
L is the length of the echo path. The error signal at time n is defined by
This error signal is used in the adaptive algorithm to adjust the L taps of the
filter, ĥ . For simplicity it is assumed that the length of the signal vector, x, is the same as
the effective length of the echo path, h. When v is not present, with any adaptive
algorithm, ĥ will quickly converge to an estimate of h, which is the best way to cancel
the echo. When x is not present, or very small, adaptation is halted by the nature of the
adaptive algorithm. When both x and v are present the near-end talker signal could
disrupt the adaptation of ĥ and cause divergence. Therefore, the goal of a double talk
detection algorithm is to stop the adaptation of ĥ when the level of v becomes significant
in relation to the level of x and to keep the adaptation going when the level of v is
negligible [4].
The basic double talk detection process starts with computing a detection statistic
and comparing it with a preset threshold. Different methods have been proposed to form
the detection statistic. The Geigel algorithm has proven successful in line echo
cancellers. However, it does not always provide reliable performance when used in
32
applications. However, for the DTD algorithms only heuristic methods have been used to
select the threshold T with little justification for the choice. In addition, there has not
Almost all types of doubletalk detectors operate in the same manner. Therefore,
the general procedure for handling double talk is described by the following four steps.
time Thold. While the detection is held the filter adaptation is disabled.
The hold time, Thold, in steps 3 and 4 is essential to suppress detection dropouts due to the
noisy behavior of the detection statistic. Although there are some possible variations
most of the DTD algorithms keep this basic form and only differ in how they form the
detection statistic.
follows:
33
• if v = 0 (doubletalk is not present), ξ ≥ T
Geigel Algorithm, the Cross- correlation Method and the Normalized Cross-Correlation
Method are presented. The DTD algorithm used in this research was the Normalized
Cross-Correlation Method.
speech whenever
max{ x (k ) ,⋅ ⋅ ⋅, x (k − N + 1) }
ξ= <T (3.23)
d (k )
where N and T are suitably chosen constants. This detection scheme is based on a
waveform level comparison between the microphone signal, d, and the far-end speech, x,
assuming the near-end speech, v, in the microphone signal will be stronger than the echo.
The maximum, or norm, of the N most recent samples of x is chosen for the comparison
due to uncertain delay in the echo path. The threshold, T, is used to compensate for the
energy level of the echo path response, h, and is often set to ½ for line echo cancellers
since the hybrid loss is typically approximately 6dB. However, for an AEC, it is not easy
to set a universal threshold that will work reliably in all the various situations since the
34
loss through the acoustic echo path can vary greatly depending on many factors. For N,
one easy choice is to set it equal to the adaptive filter length L [5].
means for double talk detection. The cross-correlation coefficient vector between x and d
is defined by
E{x (n )d (n )}
cxd = (3.24)
E{x 2 (n )}E{d 2 (n )
rxd
= (3.25)
σx σ d
where E denotes the mathematical expectation and cxd,I is the cross-correlation coefficient
ξ = c xd (3.27)
to a threshold level T. The decision rule is then very simple. If ξ ≥ T, double talk is not
The fundamental problem with this method is that the cross-correlation coefficient
0, it does not mean that ξ = 1 or any other known value. The value of ξ is not known in
general. The amount of correlation will depend greatly on the statistics of the signal and
35
of the echo path. As a result, the best value of T will vary from one experiment to
another. There is no natural threshold level associated with the variable ξ when v= 0.
These complexities lead to another DTD algorithm, which is termed the Normalized
Rdd = E{d(n)dT(n)}
= HTRxxH (3.29)
where
Since
In general, for v ≠ 0,
where
36
is the covariance matrix of the near-end speech. The new decision variable is obtained by
dividing equation(3.35) by Rdd and extracting the square root, which yields
ξ = R T xd R −1 xx R xd R −1 dd (3.37)
= c xd (3.38)
where
and equation (3.35) into equation (3.37) produces the decision variable, which is given by
H T R xx H
ξ = . (3.40)
H T R xx H + σ 2 v
Equation (3.30) shows that for v = 0; ξ = 1 and for v ≠ 0; ξ < 1. Therefore, the
threshold value can be set tone (1). It should also be noted that ξ is not sensitive to
placed in the speech path after echo cancellation in order to provide further attenuation or
removal of residual echo signals that cannot be removed completely by an echo canceller.
A non-linearity, a distortion, or an added noise signal are examples of signals that cannot
be fully cancelled by an echo canceller. Therefore, these signals are typically removed or
37
3.5.1 Noise Gate as a NLP
In this research a noise gate was used as a NLP, which is a type of dynamic
processor. Noise gates belong to the family of expanders. As the name implies, it
increases the dynamic range of a signal such that low-level signals are attenuated while
the higher-level portions are neither attenuated nor amplified. The noise gate expansion
can be taken to the extreme where it will heavily attenuate the input or eliminate it
While expanders are quite difficult to use effectively, noise gates are a very
common and effective way of reducing the apparent noise level in audio signals. The
noise gate offers a method of turning down the gain of an audio signal when the signal
level drops below some threshold value. The threshold value needs to be high enough
that only the background noise falls below but not so high that the audio signals are cut
off prematurely. Noise gates are most often used to eliminate noise or hiss that may
otherwise be amplified.
Input Ouput
Σ
38
An expander is essentially an amplifier with a variable gain control. The level of
the input signal is sensed by the level detector and applied to the gain control element.
The gain is never greater than one and is controlled by the level of the input signal.
When the input signal level is higher than a threshold value the expander has a unity gain
and acts as a normal unity gain amplifier. When the input signal level drops below the
threshold the gain decreases, which makes the signal even lower or the signal is
completely removed depending on the threshold value. This feature drove the choice of
using a noise gate as the NLP since the signal level of the echo is very much less than
which is presented in Figure 3.7. The level of the input signal is given by the horizontal
axis and the output level is given by the vertical axis. When the slope of the line is unity,
angled at 45 degrees, the gain of the expander is one (1). Therefore, the output level is
identical to the input level. A change in the line's slope means a change in the expander's
gain. For the expander, part of the line will have a larger slope. The point where the
slope of the line changes is called the threshold, which is adjustable in many expanders.
When the input signal level is above the threshold nothing happens. However, when the
input signal level drops below the threshold the gain reduction starts. The gain reduction
39
Output Level
(dB)
No Expansion
2:1 Expansion
4:1 Expansion
10:1 Expansion
(Noise Gating)
The amount of expansion that is applied is usually expressed as a ratio such as 2:1
or 4:1. This implies that while the input is below the threshold a change in the input level
produces a change in the output that is two times or four times as large. Therefore, with a
4:1 expansion ratio and the input level below the threshold a dip of 3 dB in the input will
characteristic becomes almost vertical below the threshold and when the expansion ratio
larger than 10:1, the expander is often termed a noise gate. In this case, the input signal
may be very heavily attenuated or removed entirely. Therefore, the expander acts like an
on/off switch for signals. When the signal is high enough, the switch is on and the input
appears at the output. However, when the signal drops below the threshold the switch is
off and there is no output. Hence, when the near-end signal passes through this on/off
40
switch or noise gate, because of the high signal level the switch is on and attenuation
does not occur. However, when the echo signal passes the switch is off and the echo is
Since the level sensing function is a short time average it takes some time for a
change in the input level to be detected, which triggers a change in the gain. In general
an expander is characterized by its attack and release times. The attack time is the time
required for the expander to restore the gain to one once the input level rises above the
threshold. Likewise, the time taken for the expander to reduce its gain after the input
drops below the threshold is the release time. The attack and release times give the
expander a smoother change in the gain rather than abrupt changes that may produce
pops and/or other noise. Figure 3.8 illustrates how the attack and release times affect an
41
Expander Input
Time
Expander Ouput
Time
Expander Gain
Attack Time Release Time
Time
Only the middle portion of the input is above the expander's threshold value.
However, it takes some time for the expander to increase the gain when the input level
rises above the threshold. When the input level drops below the threshold the expander
gradually reduces its gain. Therefore, a noise gate fulfilled this research’s need for a
NLP. Another important aspect of the selection was that the noise gate does not facilitate
clipping of talker’s signal, which is very common in the with other NLP types.
42
CHAPTER 4
(AEC). In this chapter the flowchart for the software simulation and the results of
simulation of the AEC algorithm, which was performed in MATLAB are discussed. The
idea that drove the simulation was to show that convincible results could be achieved in
technical computing. The salient features of MATLAB are its in-built mathematical
toolboxes and graphic functions. Additionally, external routines that are written in other
languages such as C, C++, Fortran and Java, can be integrated with MATLAB
applications. MATLAB also supports importing data from files and other external
devices. Most of the functions in MATLAB are matrix-oriented and can act on arrays of
any appropriate dimension. MATLAB also has a separate toolbox for signal processing
43
applications, which provided simpler solutions for many of the problems encountered in
this research.
The MATLAB software environment suited the needs of this research for the
following reasons:
• The input signals (far-end and near-end talker signals) were voices. These
voices were stored as wav files and the wav files were easily imported into the
code.
• The intermediate signals (echo signals) and output signals (error signal and
signals obtained after echo cancellation) were obtained as wav files. Thus the
audio of the voice signals could be literally be heard, which aided immensely
• The signal processing toolbox has in-built functions for almost all signal
processing applications. The toolbox helped the efficiency of the code since
sub-routines.
The flowchart for the simulation of the echo canceller algorithm is presented in
Figure 4.1.
44
Start
Get far-end
signal, x(n)
Create echo
signal, r(n) from
the far-end signal
Get near-end
signal, v(n)
Yes
Does Filter Loop
Doubletalk Filter coefficients
Exist are frozen
No
NLMS Loop
Update Filter
coefficients
45
4.3 Description of the Simulation Setup
This section describes the simulation environment, its requirements and the
procedures adopted.
1. The input signals, both far-end and near-end signals, were simulated and
3. A sampling rate of 8000 Hz was used for all the signals in the simulation.
4. The graphs plotted have x-axes denoting the time and y-axes denoting the
4.4 Results
simulating the algorithm in MATLAB. The plot of the far-end signal x(n) is presented in
Figure 4.2.
46
Figure 4.2: Plot of the Far-end Signal, x(n)
The far-end signal was delayed and scaled in order to produce the echo signal,
r(n), which is presented in Figure 4.3. The echo signal was produced when the far-end
47
Figure 4.3: Plot of the Echo Signal, r(n)
The echo signal was added to the near-end signal, v(n), in order to produce the
desired signal, d(n), which became the input for the adaptive filter. The plot of the near-
end signal, v(n), is presented in Figure 4.4 and the plot of the desired signal, d(n). is
48
Figure 4.4: Plot of the Near-end Signal, v(n)
detector. For the purpose of adaptive filtering the NLMS algorithm was used during the
simulation. The algorithm used the normalized cross correlation algorithm for double
talk detection.
Various parameters for the NLMS algorithm such as the convergence factor, µn,
and γ had to be set in order to avoid misadjustment. Additionally, the length of the filter
had to be established beforehand. The values of these parameters, which were used in the
simulation, are
For the purpose of the open simulation environment and faster convergence of the
algorithm, it was assumed that double talk did not take place during this simulation.
The output of this module is the error signal, e(n), which is presented in Figure
4.6. In the case of an ideal echo canceller the error signal should be the same as that of
the near-end signal, v(n). However, due to the presence of residual echo and
nonlinearities the error signal, e(n), was not a perfect copy of the near-end signal, v(n).
50
Figure 4.6: Plot of the Error Signal e(n)
Since the error signal, e(n), contained a residual echo it was passed through a
NLP. As explained earlier, a noise gate was used for the NLP in this research. The
purpose of this device was to attenuate the residual echo and to pass on the speech signal
without any clipping. Figure 4.7 presents the plot of the error signal after nonlinear
processing.
51
Figure 4.7: Plot of the Error Signal after Nonlinear Processing
Figure 4.7 clearly shows that the residual echo was completely removed and that s
no clipping occurred. Therefore, the signal output of the echo canceller was devoid of
In order to evaluate the effective working of the algorithm, some basic tests were
52
4.5.1 Convergence Test
The first and paramount test of the algorithm was whether or not the algorithm
converged. If the filter coefficients used in the adaptive algorithm did not converge, the
code would be useless. Therefore, several tests were performed on the simulated data in
order to verify the convergence of the filter coefficients. These tests were conducted by
varying the convergence factor, µn, and examining the effect on the filter coefficients and
the plot of the error signal, e(n). Through careful observation it was determined that a
In order to evaluate the quality of the echo cancellation algorithm the measure of
ERLE was used. ERLE, measured in dB is defined as the ratio of the instantaneous
power of the signal, d(n), and the instantaneous power of the residual error signal, e(n),
immediately after cancellation. ERLE measures the amount of loss introduced by the
Pd (n ) E[d 2 (n )]
ERLE = 10log = 10log . (4.1)
Pe (n ) E[e 2 (n )]
considered to be ideal. Figure 4.8 presents a plot of the ERLE with the ERLE plotted in
dB along the y-axis and the number of samples along the x-axis. The plot of ERLE
implies that the ERLE for this algorithm attained the required value.
53
Figure 4.8: Plot of ERLE Vs Number of Samples
The last test consisted of listening to the output for appropriate cancellation of
echoes. The audio of the output signals was presented to a panel of five members with no
technical expertise in this field. The panel was almost not able to distinguish the near-
end signal, v(n), and the output signal with the residual echo, e(n), removed. Some
discrepancies in the audio could be attributed to the fact that the real-time applications
54
CHAPTER 5
5.1 Conclusions
algorithm presented in this thesis successfully attempted to find a software solution for
was completely a software approach without utilizing any DSP hardware components.
The algorithm was capable of running in any PC with MATLAB software installed.
Additionally, a new method, which utilized the noise gate device for nonlinear processing
was proposed. This new technique is faster and provides almost perfect results for
canceling residual echoes without clipping of the reference speech signals. In addition,
the results obtained were convincing. The audio of the output speech signals were highly
55
5.2 Further Work
The algorithm proposed in this thesis presents a solution for single channel
acoustic echoes. However, most often in real life situations, multichannel sound is the
communicating with each other multichannel sound abounds. Since there is just a single
microphone the other end will hear just a highly incoherent monographic sound. In order
to handle such situations in a better way the echo cancellation algorithm developed
56
REFERENCES
[1] Sadaoki Furui and M. Mohan Sondhi, “Advances in Speech Signal Processing”,
Marcel Dekker, Inc, 1992
[2] Lester S.H Ngia, “System Modeling using Basis Functions and Application to Echo
Cancellation”, Ph. D. Dissertation, Chalmers University of Technology
[3] Paulo S.R. Diniz, “Adaptive Filtering Algorithms and Practical Implementation”,
Kluwer Academic Publishers, 1997
[4] J. Benesty, D.R. Morgan and J.H. Cho, “A New Class of Doubletalk Detectors
Based on Cross-correlation”, IEEE Trans. Speech Audio Processing, vol. 8, pp.
168-172, March 2000
[5] J. Benesty, T. Gansler, D.R. Morgan, M.M. Sondhi and S.L. Gay, “Advances in
Network and Acoustic Echo Cancellation”, Springer-Verlag, 2001
[7] Eargle, John, “Handbook of Recording Engineering”, Van Nostrand Reinhold, 1996
[8] Mu Tian, P.K. Gupta, Marcus Harte and Danny Yip, “Improved Echo Canceller and
Implementation”, Dialogic Corporation
[9] J.G. Proakis and D.G. Manolakis, “Digital Signal Processing - Principles,
Algorithms and Applications”, Prentice Hall, 1996
[10] A.V. Oppenheim and R.W. Schafer, “Discrete Time Signal Processing”, Prentice
Hall, 1996
57