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