Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/src/spandsp/v29rx.h @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * v29rx.h - ITU V.29 modem receive part | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2003 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU Lesser General Public License version 2.1, | |
14 * as published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU Lesser General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU Lesser General Public | |
22 * License along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: v29rx.h,v 1.72 2009/07/09 13:52:09 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \file */ | |
29 | |
30 #if !defined(_SPANDSP_V29RX_H_) | |
31 #define _SPANDSP_V29RX_H_ | |
32 | |
33 /*! \page v29rx_page The V.29 receiver | |
34 \section v29rx_page_sec_1 What does it do? | |
35 The V.29 receiver implements the receive side of a V.29 modem. This can operate | |
36 at data rates of 9600, 7200 and 4800 bits/s. The audio input is a stream of 16 | |
37 bit samples, at 8000 samples/second. The transmit and receive side of V.29 | |
38 modems operate independantly. V.29 is mostly used for FAX transmission, where it | |
39 provides the standard 9600 and 7200 bits/s rates (the 4800 bits/s mode is not | |
40 used for FAX). | |
41 | |
42 \section v29rx_page_sec_2 How does it work? | |
43 V.29 operates at 2400 baud for all three bit rates. It uses 16-QAM modulation for | |
44 9600bps, 8-QAM for 7200bps, and 4-PSK for 4800bps. A training sequence is specified | |
45 at the start of transmission, which makes the design of a V.29 receiver relatively | |
46 straightforward. | |
47 | |
48 The first stage of the training sequence consists of 128 | |
49 symbols, alternating between two constellation positions. The receiver monitors | |
50 the signal power, to sense the possible presence of a valid carrier. When the | |
51 alternating signal begins, the power rising above a minimum threshold (-26dBm0) | |
52 causes the main receiver computation to begin. The initial measured power is | |
53 used to quickly set the gain of the receiver. After this initial settling, the | |
54 front end gain is locked, and the adaptive equalizer tracks any subsequent | |
55 signal level variation. The signal is oversampled to 24000 samples/second (i.e. | |
56 signal, zero, zero, signal, zero, zero, ...) and fed to a complex root raised | |
57 cosine pulse shaping filter. This filter has been modified from the conventional | |
58 root raised cosine filter, by shifting it up the band, to be centred at the nominal | |
59 carrier frequency. This filter interpolates the samples, pulse shapes, and performs | |
60 a fractional sample delay at the same time. 48 sets of filter coefficients are used to | |
61 achieve a set of finely spaces fractional sample delays, between zero and | |
62 one sample. By choosing every fifth sample, and the appropriate set of filter | |
63 coefficients, the properly tuned symbol tracker can select data samples at 4800 | |
64 samples/second from points within 1.125 degrees of the centre and mid-points of | |
65 each symbol. The output of the filter is multiplied by a complex carrier, generated | |
66 by a DDS. The result is a baseband signal, requiring no further filtering, apart from | |
67 an adaptive equalizer. The baseband signal is fed to a T/2 adaptive equalizer. | |
68 A band edge component maximisation algorithm is used to tune the sampling, so the samples | |
69 fed to the equalizer are close to the mid point and edges of each symbol. Initially | |
70 the algorithm is very lightly damped, to ensure the symbol alignment pulls in | |
71 quickly. Because the sampling rate will not be precisely the same as the | |
72 transmitter's (the spec. says the symbol timing should be within 0.01%), the | |
73 receiver constantly evaluates and corrects this sampling throughout its | |
74 operation. During the symbol timing maintainence phase, the algorithm uses | |
75 a heavier damping. | |
76 | |
77 The carrier is specified as 1700Hz +-1Hz at the transmitter, and 1700 +-7Hz at | |
78 the receiver. The receive carrier would only be this inaccurate if the link | |
79 includes FDM sections. These are being phased out, but the design must still | |
80 allow for the worst case. Using an initial 1700Hz signal for demodulation gives | |
81 a worst case rotation rate for the constellation of about one degree per symbol. | |
82 Once the symbol timing synchronisation algorithm has been given time to lock to | |
83 the symbol timing of the initial alternating pattern, the phase of the demodulated | |
84 signal is recorded on two successive symbols - once for each of the constellation | |
85 positions. The receiver then tracks the symbol alternations, until a large phase jump | |
86 occurs. This signifies the start of the next phase of the training sequence. At this | |
87 point the total phase shift between the original recorded symbol phase, and the | |
88 symbol phase just before the phase jump occurred is used to provide a coarse | |
89 estimation of the rotation rate of the constellation, and it current absolute | |
90 angle of rotation. These are used to update the current carrier phase and phase | |
91 update rate in the carrier DDS. The working data already in the pulse shaping | |
92 filter and equalizer buffers is given a similar step rotation to pull it all | |
93 into line. From this point on, a heavily damped integrate and dump approach, | |
94 based on the angular difference between each received constellation position and | |
95 its expected position, is sufficient to track the carrier, and maintain phase | |
96 alignment. A fast rough approximator for the arc-tangent function is adequate | |
97 for the estimation of the angular error. | |
98 | |
99 The next phase of the training sequence is a scrambled sequence of two | |
100 particular symbols. We train the T/2 adaptive equalizer using this sequence. The | |
101 scrambling makes the signal sufficiently diverse to ensure the equalizer | |
102 converges to the proper generalised solution. At the end of this sequence, the | |
103 equalizer should be sufficiently well adapted that is can correctly resolve the | |
104 full QAM constellation. However, the equalizer continues to adapt throughout | |
105 operation of the modem, fine tuning on the more complex data patterns of the | |
106 full QAM constellation. | |
107 | |
108 In the last phase of the training sequence, the modem enters normal data | |
109 operation, with a short defined period of all ones as data. As in most high | |
110 speed modems, data in a V.29 modem passes through a scrambler, to whiten the | |
111 spectrum of the signal. The transmitter should initialise its data scrambler, | |
112 and pass the ones through it. At the end of the ones, real data begins to pass | |
113 through the scrambler, and the transmit modem is in normal operation. The | |
114 receiver tests that ones are really received, in order to verify the modem | |
115 trained correctly. If all is well, the data following the ones is fed to the | |
116 application, and the receive modem is up and running. Unfortunately, some | |
117 transmit side of some real V.29 modems fail to initialise their scrambler before | |
118 sending the ones. This means the first 23 received bits (the length of the | |
119 scrambler register) cannot be trusted for the test. The receive modem, | |
120 therefore, only tests that bits starting at bit 24 are really ones. | |
121 */ | |
122 | |
123 typedef void (*qam_report_handler_t)(void *user_data, const complexf_t *constel, const complexf_t *target, int symbol); | |
124 | |
125 /*! | |
126 V.29 modem receive side descriptor. This defines the working state for a | |
127 single instance of a V.29 modem receiver. | |
128 */ | |
129 typedef struct v29_rx_state_s v29_rx_state_t; | |
130 | |
131 #if defined(__cplusplus) | |
132 extern "C" | |
133 { | |
134 #endif | |
135 | |
136 /*! Initialise a V.29 modem receive context. | |
137 \brief Initialise a V.29 modem receive context. | |
138 \param s The modem context. | |
139 \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600. | |
140 \param put_bit The callback routine used to put the received data. | |
141 \param user_data An opaque pointer passed to the put_bit routine. | |
142 \return A pointer to the modem context, or NULL if there was a problem. */ | |
143 SPAN_DECLARE(v29_rx_state_t *) v29_rx_init(v29_rx_state_t *s, int bit_rate, put_bit_func_t put_bit, void *user_data); | |
144 | |
145 /*! Reinitialise an existing V.29 modem receive context. | |
146 \brief Reinitialise an existing V.29 modem receive context. | |
147 \param s The modem context. | |
148 \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600. | |
149 \param old_train TRUE if a previous trained values are to be reused. | |
150 \return 0 for OK, -1 for bad parameter */ | |
151 SPAN_DECLARE(int) v29_rx_restart(v29_rx_state_t *s, int bit_rate, int old_train); | |
152 | |
153 /*! Release a V.29 modem receive context. | |
154 \brief Release a V.29 modem receive context. | |
155 \param s The modem context. | |
156 \return 0 for OK */ | |
157 SPAN_DECLARE(int) v29_rx_release(v29_rx_state_t *s); | |
158 | |
159 /*! Free a V.29 modem receive context. | |
160 \brief Free a V.29 modem receive context. | |
161 \param s The modem context. | |
162 \return 0 for OK */ | |
163 SPAN_DECLARE(int) v29_rx_free(v29_rx_state_t *s); | |
164 | |
165 /*! Get the logging context associated with a V.29 modem receive context. | |
166 \brief Get the logging context associated with a V.29 modem receive context. | |
167 \param s The modem context. | |
168 \return A pointer to the logging context */ | |
169 SPAN_DECLARE(logging_state_t *) v29_rx_get_logging_state(v29_rx_state_t *s); | |
170 | |
171 /*! Change the put_bit function associated with a V.29 modem receive context. | |
172 \brief Change the put_bit function associated with a V.29 modem receive context. | |
173 \param s The modem context. | |
174 \param put_bit The callback routine used to handle received bits. | |
175 \param user_data An opaque pointer. */ | |
176 SPAN_DECLARE(void) v29_rx_set_put_bit(v29_rx_state_t *s, put_bit_func_t put_bit, void *user_data); | |
177 | |
178 /*! Change the modem status report function associated with a V.29 modem receive context. | |
179 \brief Change the modem status report function associated with a V.29 modem receive context. | |
180 \param s The modem context. | |
181 \param handler The callback routine used to report modem status changes. | |
182 \param user_data An opaque pointer. */ | |
183 SPAN_DECLARE(void) v29_rx_set_modem_status_handler(v29_rx_state_t *s, modem_rx_status_func_t handler, void *user_data); | |
184 | |
185 /*! Process a block of received V.29 modem audio samples. | |
186 \brief Process a block of received V.29 modem audio samples. | |
187 \param s The modem context. | |
188 \param amp The audio sample buffer. | |
189 \param len The number of samples in the buffer. | |
190 \return The number of samples unprocessed. */ | |
191 SPAN_DECLARE_NONSTD(int) v29_rx(v29_rx_state_t *s, const int16_t amp[], int len); | |
192 | |
193 /*! Fake processing of a missing block of received V.29 modem audio samples. | |
194 (e.g due to packet loss). | |
195 \brief Fake processing of a missing block of received V.29 modem audio samples. | |
196 \param s The modem context. | |
197 \param len The number of samples to fake. | |
198 \return The number of samples unprocessed. */ | |
199 SPAN_DECLARE(int) v29_rx_fillin(v29_rx_state_t *s, int len); | |
200 | |
201 /*! Get a snapshot of the current equalizer coefficients. | |
202 \brief Get a snapshot of the current equalizer coefficients. | |
203 \param s The modem context. | |
204 \param coeffs The vector of complex coefficients. | |
205 \return The number of coefficients in the vector. */ | |
206 #if defined(SPANDSP_USE_FIXED_POINT) | |
207 SPAN_DECLARE(int) v29_rx_equalizer_state(v29_rx_state_t *s, complexi16_t **coeffs); | |
208 #else | |
209 SPAN_DECLARE(int) v29_rx_equalizer_state(v29_rx_state_t *s, complexf_t **coeffs); | |
210 #endif | |
211 | |
212 /*! Get the current received carrier frequency. | |
213 \param s The modem context. | |
214 \return The frequency, in Hertz. */ | |
215 SPAN_DECLARE(float) v29_rx_carrier_frequency(v29_rx_state_t *s); | |
216 | |
217 /*! Get the current symbol timing correction since startup. | |
218 \param s The modem context. | |
219 \return The correction. */ | |
220 SPAN_DECLARE(float) v29_rx_symbol_timing_correction(v29_rx_state_t *s); | |
221 | |
222 /*! Get the current received signal power. | |
223 \param s The modem context. | |
224 \return The signal power, in dBm0. */ | |
225 SPAN_DECLARE(float) v29_rx_signal_power(v29_rx_state_t *s); | |
226 | |
227 /*! Set the power level at which the carrier detection will cut in | |
228 \param s The modem context. | |
229 \param cutoff The signal cutoff power, in dBm0. */ | |
230 SPAN_DECLARE(void) v29_rx_signal_cutoff(v29_rx_state_t *s, float cutoff); | |
231 | |
232 /*! Set a handler routine to process QAM status reports | |
233 \param s The modem context. | |
234 \param handler The handler routine. | |
235 \param user_data An opaque pointer passed to the handler routine. */ | |
236 SPAN_DECLARE(void) v29_rx_set_qam_report_handler(v29_rx_state_t *s, qam_report_handler_t handler, void *user_data); | |
237 | |
238 #if defined(__cplusplus) | |
239 } | |
240 #endif | |
241 | |
242 #endif | |
243 /*- End of file ------------------------------------------------------------*/ |