v29tx.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * v29tx.h - ITU V.29 modem transmit part
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2003 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 2.1,
00014  * as published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: v29tx.h,v 1.34 2008/07/16 14:23:48 steveu Exp $
00026  */
00027 
00028 /*! \file */
00029 
00030 #if !defined(_SPANDSP_V29TX_H_)
00031 #define _SPANDSP_V29TX_H_
00032 
00033 /*! \page v29tx_page The V.29 transmitter
00034 \section v29tx_page_sec_1 What does it do?
00035 The V.29 transmitter implements the transmit side of a V.29 modem. This can
00036 operate at data rates of 9600, 7200 and 4800 bits/s. The audio output is a
00037 stream of 16 bit samples, at 8000 samples/second. The transmit and receive side
00038 of V.29 modems operate independantly. V.29 is mostly used for FAX transmission,
00039 where it provides the standard 9600 and 7200 bits/s rates (the 4800 bits/s mode
00040 is not used for FAX). 
00041 
00042 \section v29tx_page_sec_2 How does it work?
00043 V.29 uses QAM modulation. The standard method of producing a QAM modulated
00044 signal is to use a sampling rate which is a multiple of the baud rate. The raw
00045 signal is then a series of complex pulses, each an integer number of samples
00046 long. These can be shaped, using a suitable complex filter, and multiplied by a
00047 complex carrier signal to produce the final QAM signal for transmission. 
00048 
00049 The pulse shaping filter is only vaguely defined by the V.29 spec. Some of the
00050 other ITU modem specs. fully define the filter, typically specifying a root
00051 raised cosine filter, with 50% excess bandwidth. This is a pity, since it
00052 increases the variability of the received signal. However, the receiver's
00053 adaptive equalizer will compensate for these differences. The current
00054 design uses a root raised cosine filter with 25% excess bandwidth. Greater
00055 excess bandwidth will not allow the tranmitted signal to meet the spectral
00056 requirements.
00057 
00058 The sampling rate for our transmitter is defined by the channel - 8000 per
00059 second. This is not a multiple of the baud rate (i.e. 2400 baud). The baud
00060 interval is actually 10/3 sample periods. Instead of using a symmetric
00061 FIR to pulse shape the signal, a polyphase filter is used. This consists of
00062 10 sets of coefficients, offering zero to 9/10ths of a baud phase shift as well
00063 as root raised cosine filtering. The appropriate coefficient set is chosen for
00064 each signal sample generated.
00065 
00066 The carrier is generated using the DDS method. Using two second order resonators,
00067 started in quadrature, might be more efficient, as it would have less impact on
00068 the processor cache than a table lookup approach. However, the DDS approach
00069 suits the receiver better, so the same signal generator is also used for the
00070 transmitter. 
00071 
00072 The equation defining QAM modulation is:
00073 
00074     s(n) = A*cos(2*pi*f*n + phi(n))
00075 
00076 where phi(n) is the phase of the information, and A is the amplitude of the information
00077 
00078 using the identity
00079 
00080     cos(x + y) = cos(x)*cos(y) - sin(x)*sin(y)
00081     
00082 we get
00083 
00084     s(n) = A {cos(2*pi*f*n)*cos(phi(n)) - sin(2*pi*f*n)*sin(phi(n))}
00085     
00086 substituting with the constellation positions
00087 
00088     I(n) = A*cos(phi(n))
00089     Q(n) = A*sin(phi(n))
00090     
00091 gives
00092 
00093     s(n) = I(n)*cos(2*pi*f*n) - Q(n)*sin(2*pi*f*n)
00094 
00095 */
00096 
00097 #define V29_TX_FILTER_STEPS     9
00098 
00099 /*!
00100     V.29 modem transmit side descriptor. This defines the working state for a
00101     single instance of a V.29 modem transmitter.
00102 */
00103 typedef struct
00104 {
00105     /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */
00106     int bit_rate;
00107     /*! \brief The callback function used to get the next bit to be transmitted. */
00108     get_bit_func_t get_bit;
00109     /*! \brief A user specified opaque pointer passed to the get_bit function. */
00110     void *get_bit_user_data;
00111 
00112     /*! \brief The callback function used to report modem status changes. */
00113     modem_tx_status_func_t status_handler;
00114     /*! \brief A user specified opaque pointer passed to the status function. */
00115     void *status_user_data;
00116 
00117     /*! \brief Gain required to achieve the specified output power, not allowing
00118                for the size of the current constellation. */
00119     float base_gain;
00120     /*! \brief Gain required to achieve the specified output power, allowing
00121                for the size of the current constellation. */
00122 #if defined(SPANDSP_USE_FIXED_POINT)
00123     int32_t gain;
00124 #else
00125     float gain;
00126 #endif
00127 
00128     /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
00129 #if defined(SPANDSP_USE_FIXED_POINT)
00130     complexi16_t rrc_filter[2*V29_TX_FILTER_STEPS];
00131 #else
00132     complexf_t rrc_filter[2*V29_TX_FILTER_STEPS];
00133 #endif
00134     /*! \brief Current offset into the RRC pulse shaping filter buffer. */
00135     int rrc_filter_step;
00136 
00137     /*! \brief The register for the data scrambler. */
00138     unsigned int scramble_reg;
00139     /*! \brief The register for the training scrambler. */
00140     uint8_t training_scramble_reg;
00141     /*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
00142                FALSE if transmitting user data. */
00143     int in_training;
00144     /*! \brief A counter used to track progress through sending the training sequence. */
00145     int training_step;
00146     /*! \brief An offset value into the table of training parameters, used to match the
00147                training pattern to the bit rate. */
00148     int training_offset;
00149 
00150     /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
00151     uint32_t carrier_phase;
00152     /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
00153     int32_t carrier_phase_rate;
00154     /*! \brief The current fractional phase of the baud timing. */
00155     int baud_phase;
00156     /*! \brief The code number for the current position in the constellation. */
00157     int constellation_state;
00158     /*! \brief The get_bit function in use at any instant. */
00159     get_bit_func_t current_get_bit;
00160     /*! \brief Error and flow logging control */
00161     logging_state_t logging;
00162 } v29_tx_state_t;
00163 
00164 #if defined(__cplusplus)
00165 extern "C"
00166 {
00167 #endif
00168 
00169 /*! Adjust a V.29 modem transmit context's power output.
00170     \brief Adjust a V.29 modem transmit context's output power.
00171     \param s The modem context.
00172     \param power The power level, in dBm0 */
00173 void v29_tx_power(v29_tx_state_t *s, float power);
00174 
00175 /*! Initialise a V.29 modem transmit context. This must be called before the first
00176     use of the context, to initialise its contents.
00177     \brief Initialise a V.29 modem transmit context.
00178     \param s The modem context.
00179     \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600.
00180     \param tep TRUE is the optional TEP tone is to be transmitted.
00181     \param get_bit The callback routine used to get the data to be transmitted.
00182     \param user_data An opaque pointer.
00183     \return A pointer to the modem context, or NULL if there was a problem. */
00184 v29_tx_state_t *v29_tx_init(v29_tx_state_t *s, int bit_rate, int tep, get_bit_func_t get_bit, void *user_data);
00185 
00186 /*! Reinitialise an existing V.29 modem transmit context, so it may be reused.
00187     \brief Reinitialise an existing V.29 modem transmit context.
00188     \param s The modem context.
00189     \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600.
00190     \param tep TRUE is the optional TEP tone is to be transmitted.
00191     \return 0 for OK, -1 for bad parameter */
00192 int v29_tx_restart(v29_tx_state_t *s, int bit_rate, int tep);
00193 
00194 /*! Free a V.29 modem transmit context.
00195     \brief Free a V.29 modem transmit context.
00196     \param s The modem context.
00197     \return 0 for OK */
00198 int v29_tx_free(v29_tx_state_t *s);
00199 
00200 /*! Change the get_bit function associated with a V.29 modem transmit context.
00201     \brief Change the get_bit function associated with a V.29 modem transmit context.
00202     \param s The modem context.
00203     \param get_bit The callback routine used to get the data to be transmitted.
00204     \param user_data An opaque pointer. */
00205 void v29_tx_set_get_bit(v29_tx_state_t *s, get_bit_func_t get_bit, void *user_data);
00206 
00207 /*! Change the modem status report function associated with a V.29 modem transmit context.
00208     \brief Change the modem status report function associated with a V.29 modem transmit context.
00209     \param s The modem context.
00210     \param handler The callback routine used to report modem status changes.
00211     \param user_data An opaque pointer. */
00212 void v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_tx_status_func_t handler, void *user_data);
00213 
00214 /*! Generate a block of V.29 modem audio samples.
00215     \brief Generate a block of V.29 modem audio samples.
00216     \param s The modem context.
00217     \param amp The audio sample buffer.
00218     \param len The number of samples to be generated.
00219     \return The number of samples actually generated.
00220 */
00221 int v29_tx(v29_tx_state_t *s, int16_t *amp, int len);
00222 
00223 #if defined(__cplusplus)
00224 }
00225 #endif
00226 
00227 #endif
00228 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:50 2008 for spandsp by  doxygen 1.5.6