spandsp: Line echo cancellation for modems

spandsp 0.0.6

Line echo cancellation for modems

# What does it do?

This module aims to cancel electrical echoes (e.g. from 2-4 wire hybrids) in modem applications. It is not very suitable for speech applications, which require additional refinements for satisfactory performance. It is, however, more efficient and better suited to modem applications.

# How does it work?

The heart of the echo cancellor is an adaptive FIR filter. This is adapted to match the impulse response of the environment being cancelled. It must be long enough to adequately cover the duration of that impulse response. The signal being transmitted into the environment being cancelled is passed through the FIR filter. The resulting output is an estimate of the echo signal. This is then subtracted from the received signal, and the result should be an estimate of the signal which originates within the environment being cancelled (people talking in the room, or the signal from the far end of a telephone line) free from the echos of our own transmitted signal.

The FIR filter is adapted using the least mean squares (LMS) algorithm. This algorithm is attributed to Widrow and Hoff, and was introduced in 1960. It is the commonest form of filter adaption used in things like modem line equalisers and line echo cancellers. It works very well if the signal level is constant, which is true for a modem signal. To ensure good performa certain conditions must be met:

    - The transmitted signal has weak self-correlation.
    - There is no signal being generated within the environment being cancelled.

The difficulty is that neither of these can be guaranteed. If the adaption is performed while transmitting noise (or something fairly noise like, such as voice) the adaption works very well. If the adaption is performed while transmitting something highly correlative (e.g. tones, like DTMF), the adaption can go seriously wrong. The reason is there is only one solution for the adaption on a near random signal. For a repetitive signal, there are a number of solutions which converge the adaption, and nothing guides the adaption to choose the correct one.

# How do I use it?

The echo cancellor processes both the transmit and receive streams sample by sample. The processing function is not declared inline. Unfortunately, cancellation requires many operations per sample, so the call overhead is only a minor burden.