spandsp  3.0.0
modem_echo.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * modem_echo.h - An echo cancellor, suitable for electrical echos in GSTN modems
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2001, 2004 Steve Underwood
9  *
10  * Based on a bit from here, a bit from there, eye of toad,
11  * ear of bat, etc - plus, of course, my own 2 cents.
12  *
13  * All rights reserved.
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU Lesser General Public License version 2.1,
17  * as published by the Free Software Foundation.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this program; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28 
29 /*! \file */
30 
31 #if !defined(_SPANDSP_MODEM_ECHO_H_)
32 #define _SPANDSP_MODEM_ECHO_H_
33 
34 /*! \page modem_echo_can_page Line echo cancellation for modems
35 
36 \section modem_echo_can_page_sec_1 What does it do?
37 This module aims to cancel electrical echoes (e.g. from 2-4 wire hybrids)
38 in modem applications. It is not very suitable for speech applications, which
39 require additional refinements for satisfactory performance. It is, however, more
40 efficient and better suited to modem applications.
41 
42 \section modem_echo_can_page_sec_2 How does it work?
43 The heart of the echo cancellor is an adaptive FIR filter. This is adapted to
44 match the impulse response of the environment being cancelled. It must be long
45 enough to adequately cover the duration of that impulse response. The signal
46 being transmitted into the environment being cancelled is passed through the
47 FIR filter. The resulting output is an estimate of the echo signal. This is
48 then subtracted from the received signal, and the result should be an estimate
49 of the signal which originates within the environment being cancelled (people
50 talking in the room, or the signal from the far end of a telephone line) free
51 from the echos of our own transmitted signal.
52 
53 The FIR filter is adapted using the least mean squares (LMS) algorithm. This
54 algorithm is attributed to Widrow and Hoff, and was introduced in 1960. It is
55 the commonest form of filter adaption used in things like modem line equalisers
56 and line echo cancellers. It works very well if the signal level is constant,
57 which is true for a modem signal. To ensure good performa certain conditions must
58 be met:
59 
60  - The transmitted signal has weak self-correlation.
61  - There is no signal being generated within the environment being cancelled.
62 
63 The difficulty is that neither of these can be guaranteed. If the adaption is
64 performed while transmitting noise (or something fairly noise like, such as
65 voice) the adaption works very well. If the adaption is performed while
66 transmitting something highly correlative (e.g. tones, like DTMF), the adaption
67 can go seriously wrong. The reason is there is only one solution for the
68 adaption on a near random signal. For a repetitive signal, there are a number of
69 solutions which converge the adaption, and nothing guides the adaption to choose
70 the correct one.
71 
72 \section modem_echo_can_page_sec_3 How do I use it?
73 The echo cancellor processes both the transmit and receive streams sample by
74 sample. The processing function is not declared inline. Unfortunately,
75 cancellation requires many operations per sample, so the call overhead is only a
76 minor burden.
77 */
78 
79 #include "fir.h"
80 
81 /*!
82  Modem line echo canceller descriptor. This defines the working state for a line
83  echo canceller.
84 */
86 
88 
89 #if defined(__cplusplus)
90 extern "C"
91 {
92 #endif
93 
94 /*! Create a modem echo canceller context.
95  \param len The length of the canceller, in samples.
96  eturn The new canceller context, or NULL if the canceller could not be created.
97 */
99 
100 /*! Free a modem echo canceller context.
101  \param ec The echo canceller context.
102 */
104 
105 /*! Flush (reinitialise) a modem echo canceller context.
106  \param ec The echo canceller context.
107 */
109 
110 /*! Set the adaption mode of a modem echo canceller context.
111  \param ec The echo canceller context.
112  \param adapt The mode.
113 */
114 SPAN_DECLARE(void) modem_echo_can_adaption_mode(modem_echo_can_segment_state_t *ec, int adapt);
115 
116 /*! Process a sample through a modem echo canceller.
117  \param ec The echo canceller context.
118  \param tx The transmitted audio sample.
119  \param rx The received audio sample.
120  eturn The clean (echo cancelled) received sample.
121 */
122 SPAN_DECLARE(int16_t) modem_echo_can_update(modem_echo_can_segment_state_t *ec, int16_t tx, int16_t rx);
123 
124 #if defined(__cplusplus)
125 }
126 #endif
127 
128 #endif
129 /*- End of file ------------------------------------------------------------*/
void modem_echo_can_segment_free(modem_echo_can_segment_state_t *ec)
Definition: modem_echo.c:147
void modem_echo_can_adaption_mode(modem_echo_can_segment_state_t *ec, int adapt)
Definition: modem_echo.c:76
Definition: private/modem_echo.h:41
modem_echo_can_segment_state_t * modem_echo_can_segment_init(int len)
Definition: modem_echo.c:156
int16_t modem_echo_can_update(modem_echo_can_segment_state_t *ec, int16_t tx, int16_t rx)
Definition: modem_echo.c:82
Definition: private/modem_echo.h:62
void modem_echo_can_flush(modem_echo_can_segment_state_t *ec)
Definition: modem_echo.c:64