I posted this to Whirlpool a while ago, about how Echo works, what
causes it, and how you can get around it. It's reprinted here for your
reading pleasure.

username_taken writes...

..hideous echo coming from the GXP-2000's.

Actually, the GXP's don't generate echo (well, they do, a bit. But
you don't notice it. See below). Echo is a perfectly normal part of the
telephone process. When you call someone (PSTN to PSTN) there is
_always_ echo. But, here's the tricky part. You don't notice it. When
the delay is less than 5msec, it merges with the
(I'm-using-a-two-wire-phone-)side­ tone (which is the sound of your own
voice in your earpiece) and basically vanishes from your awareness.

The reason why it's so incredibly visible in VoIP systems is that
there's an added delay (could be up to 100msec, 1/10th of a second, on
a slow machine with transcoding) put onto the audio stream. Without
echo cancellation, calling any phone that has two wires for the audio
signal, no matter how it's connected, will be pretty much useless.

This doesn't _have_ to happen at the remote end, by the way. If
you're using an X100P card in Australia, you will pretty much always
have totally awful echo, due to the impedance mismatch of the
Australian phone system (600 ohms) and the American (900 ohms). The
X100's have no functionality to change the impedance, so you're pretty
much stuck with it. You _can_ be lucky, and be extremely close to the
exchange, and have bugger all echo problems. But this is _really_
close. I don't know of anyone more than 500m away who's been able to
use an X100P and have a good audio path. (Although, if you have older
copper [thicker] to your place, you've got a better chance of having no
echo with an X100. There's a reason for this, but I don't know what it
is 8)

The TDM400's have programmable FXO and FXS ports, and then can
actually 'train' themselves to your phone line (see the incredibly
poorly documented fxotune in /usr/src/zaptel - I should write something
down about what it does and how it works one day). By setting
'opermode=AUSTRALIA' on the command line of the wctdm kernel module, it
sets the card to the correct impedance, ring voltage, and other various
arcane things which I haven't decoded yet)

Now, your home PSTN line has _already_ got an echo canceler on it,
but it only cuts in when you're calling someone far away - the other
side of the country, or internationally. You'll find that the places
you expect to have echo, that are far away, have none. This is normal.
This is Telstra doing it's job 8) You have to only care about the short
echos of your own sidetone and the short remote echo (Note, this
_isn't_ true for an ISDN link.You don't have a two wire system, so you
don't have a sidetone - no immediate short echo. Yay. But, you can
still have short and long echo's too, depending on where you're calling
and how their phone is connected. Also, you may or may not have
'someone' doing your long echo cancellation for you, too — eg,
depending on where you call, you _may_ have echo cancellation on
international calls, but you definitely won't on STD calls). This is
where the zaptel echo canceler comes in, and it does a fair-to-middlin'
job of this, when you're using the MG2 EC.

So, for those that are struggling to catch up - you're using a
standard POTS line (Plain Old Telephone Service, eg, a two-wire
standard telstra line). You pick up the phone, dial '1' and blow into
the mouthpiece. That's your sidetone, and is your first source of echo
- this is usually easily dealt with if your FXO port is configured
correctly (eg, not a X100P 8) However, you may also have remote end
echo. When you call Fred down the street, his two wire system is
generating echo too, but depending on how far 'down the street' is -
you live in cairns, and Fred might live in melbourne - they're all on
highway 1! 8) you may or may not get remote end echo. Realistically,
this is rarely a cause of echo problems on a PSTN line, it's usually
local echo that causes grief. Telstra are pretty good with their EC
stuff. (Fred could also be using a speakerphone which is causing far
end echo. It gets complex)

However, username_taken has a digital system. An ISDN circuit
(usually) has no echo cancellation on it, which means you have to
handle it yourself. This can be done (simply, very well, and
expensively) by buying a hardware echo canceler, which is full of DSP's
and various funky stuff, and plugging it in. All your echo problems go
away. Or, it can be done (reasonably simply, kinda OK, and for free)
with the zaptel echo canceler. There were some bad, nasty bugs with the
pre-1.2 trunk EC's, including them overflowing when the echo was too
loud (this is how people have mentioned they 'fixed' their echo by
turning down txgain - it just means that the EC isn't overflowing. If
the user shouts, they'll get their echo straight back again), and
various other silly, but difficult to find bugs.

Now, as I mentioned at the top, there's also a third source of
echo, but you don't notice it - the other party does. It's local echo.
This is caused, most of the time, by a telephone that doesn't have
acoustic shielding in the handset between the microphone and speaker.
The noise travels down the inside of the handpiece, is picked up by the
microphone, and the person at the _other end_ hears what they said,
faintly.

Now, finally, to the the point of this saga: that VoIP phone's
don't 'cause' echo. They just make it audible by introducing an extra
delay. The reason why people go 'Geez, those GXP-2000's cause terrible
echo' is because they have just got an X100P card, they've plugged in
into their PSTN line, and they have a bloody awful setup. They use
_anything_ and they'll have terrible echo. However, they hear that
people don't have echo so they go, 'well, it kinda works. I'll get a
TDM400 and a polycom' or something like that - by getting rid of their
untuned, $2 FXO card, they've fixed the cause of their echo. Spending
$500 on the phone was just so they had a funky phone on their desk 8)
(GXP's, by the way, DID used to case echo, by them having no echo
cancellation on their speakphones, which means that as soon as you
stuck your phone on hands free, the person at the other end hated you
with a passion. This has been fixed in the current versions)

Any more echo questions? I think I've covered most of the stuff you
'need to know' - there are other things like 'complex echos' (eg, the
'old' conferencing method was splitting the tx and rx out [causing
echo], sticking all the tx lines into an amplifier, and firing them
back out into the rx of everyone's line [again causing echo]), and how
you can disable ec on your home line to play with it (that tone that
faxes and modems beep at the start? That's a 'turn echo cancelation
off' signal to the exchange), and all sorts of other things.

PS: I just realised, I didn't emphasise the point of this post.
Edit the file /usr/src/zaptel/zconfig.h, and find the three lines that
say:

  1. define ECHO_CAN_KB1

/* This is the new latest and greatest */

/* #define ECHO_CAN_MG2 */

Change them around You want to have KB1 commented out, and MG2 enabled:

/* #define ECHO_CAN_KB1 */

/* This is the new latest and greatest */

  1. define ECHO_CAN_MG2

Type 'make install' and then stop asterisk, reload the modules, and
start asterisk again. You're now running the 'good' echo canceler! You
can check this by doing a 'dmesg' after you 'modprobe zaptel' - it
should say something like this on the last two lines:

Zapata Telephony Interface Registered on major 196

Zaptel Version: SVN-trunk-r969 Echo Canceler: MG2

--Rob

Asterisk x100p echotraining article at voip-info.org - also see this comment.

Solving Common Echo Problem article at VOIPSpeak.net