private/v17rx.h
/*
* SpanDSP - a series of DSP components for telephony
*
* private/v17rx.h - ITU V.17 modem receive part
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2003 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(_SPANDSP_PRIVATE_V17RX_H_)
#define _SPANDSP_PRIVATE_V17RX_H_
/* Target length for the equalizer is about 63 taps, to deal with the worst stuff
in V.56bis. */
/*! The length of the equalizer buffer */
//#define V17_EQUALIZER_LEN 33
#define V17_EQUALIZER_LEN 17
/*! Samples before the target position in the equalizer buffer */
//#define V17_EQUALIZER_PRE_LEN 16
#define V17_EQUALIZER_PRE_LEN 8
/*! The number of taps in the pulse shaping/bandpass filter */
#define V17_RX_FILTER_STEPS 27
/* We can store more trellis depth that we look back over, so that we can push out a group
of symbols in one go, giving greater processing efficiency, at the expense of a bit more
latency through the modem. */
/* Right now we don't take advantage of this optimisation. */
/*! The depth of the trellis buffer */
#define V17_TRELLIS_STORAGE_DEPTH 16
/*! How far we look back into history for trellis decisions */
#define V17_TRELLIS_LOOKBACK_DEPTH 16
/*!
V.17 modem receive side descriptor. This defines the working state for a
single instance of a V.17 modem receiver.
*/
struct v17_rx_state_s
{
/*! \brief The bit rate of the modem. Valid values are 7200 9600, 12000 and 14400. */
int bit_rate;
/*! \brief The callback function used to put each bit received. */
put_bit_func_t put_bit;
/*! \brief A user specified opaque pointer passed to the put_but routine. */
void *put_bit_user_data;
/*! \brief The callback function used to report modem status changes. */
modem_status_func_t status_handler;
/*! \brief A user specified opaque pointer passed to the status function. */
void *status_user_data;
/*! \brief A callback function which may be enabled to report every symbol's
constellation position. */
qam_report_handler_t qam_report;
/*! \brief A user specified opaque pointer passed to the qam_report callback
routine. */
void *qam_user_data;
#if 1 //defined(RESCALER_TEST)
/* Experimental data for AGC tolerance */
int16_t power_window[40];
int power_window_ptr;
int64_t window_power;
int64_t window_power_save;
#endif
#if defined(SPANDSP_USE_FIXED_POINTx)
/*! \brief The scaling factor accessed by the AGC algorithm. */
float agc_scaling;
/*! \brief The previous value of agc_scaling, needed to reuse old training. */
float agc_scaling_save;
/*! \brief The current delta factor for updating the equalizer coefficients. */
float eq_delta;
/*! \brief The adaptive equalizer coefficients. */
complexi16_t eq_coeff[V17_EQUALIZER_LEN];
/*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
complexi16_t eq_coeff_save[V17_EQUALIZER_LEN];
/*! \brief The equalizer signal buffer. */
complexi16_t eq_buf[V17_EQUALIZER_LEN];
/*! Low band edge filter for symbol sync. */
int32_t symbol_sync_low[2];
/*! High band edge filter for symbol sync. */
int32_t symbol_sync_high[2];
/*! DC filter for symbol sync. */
int32_t symbol_sync_dc_filter[2];
/*! Baud phase for symbol sync. */
int32_t baud_phase;
/*! \brief A measure of how much mismatch there is between the real constellation,
and the decoded symbol positions. */
float training_error;
/*! \brief The proportional part of the carrier tracking filter. */
float carrier_track_p;
/*! \brief The integral part of the carrier tracking filter. */
float carrier_track_i;
/*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
int16_t rrc_filter[V17_RX_FILTER_STEPS];
/*! \brief A pointer to the current constellation. */
const complexi16_t *constellation;
#else
/*! \brief The scaling factor accessed by the AGC algorithm. */
float agc_scaling;
/*! \brief The previous value of agc_scaling, needed to reuse old training. */
float agc_scaling_save;
/*! \brief The current delta factor for updating the equalizer coefficients. */
float eq_delta;
/*! \brief The adaptive equalizer coefficients. */
complexf_t eq_coeff[V17_EQUALIZER_LEN];
/*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
complexf_t eq_coeff_save[V17_EQUALIZER_LEN];
/*! \brief The equalizer signal buffer. */
complexf_t eq_buf[V17_EQUALIZER_LEN];
/*! Low band edge filter for symbol sync. */
float symbol_sync_low[2];
/*! High band edge filter for symbol sync. */
float symbol_sync_high[2];
/*! DC filter for symbol sync. */
float symbol_sync_dc_filter[2];
/*! Baud phase for symbol sync. */
float baud_phase;
/*! \brief A measure of how much mismatch there is between the real constellation,
and the decoded symbol positions. */
float training_error;
/*! \brief The proportional part of the carrier tracking filter. */
float carrier_track_p;
/*! \brief The integral part of the carrier tracking filter. */
float carrier_track_i;
/*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
float rrc_filter[V17_RX_FILTER_STEPS];
/*! \brief A pointer to the current constellation. */
const complexf_t *constellation;
#endif
/*! \brief Current offset into the RRC pulse shaping filter buffer. */
int rrc_filter_step;
/*! \brief The current state of the differential decoder */
int diff;
/*! \brief The register for the data scrambler. */
uint32_t scramble_reg;
/*! \brief Scrambler tap */
//int scrambler_tap;
/*! \brief TRUE if the short training sequence is to be used. */
int short_train;
/*! \brief The section of the training data we are currently in. */
int training_stage;
/*! \brief A count of how far through the current training step we are. */
int training_count;
/*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
int16_t last_sample;
/*! \brief >0 if a signal above the minimum is present. It may or may not be a V.17 signal. */
int signal_present;
/*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
int carrier_drop_pending;
/*! \brief A count of the current consecutive samples below the carrier off threshold. */
int low_samples;
/*! \brief A highest magnitude sample seen. */
int16_t high_sample;
/*! \brief The current phase of the carrier (i.e. the DDS parameter). */
uint32_t carrier_phase;
/*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
int32_t carrier_phase_rate;
/*! \brief The carrier update rate saved for reuse when using short training. */
int32_t carrier_phase_rate_save;
/*! \brief A power meter, to measure the HPF'ed signal power in the channel. */
power_meter_t power;
/*! \brief The power meter level at which carrier on is declared. */
int32_t carrier_on_power;
/*! \brief The power meter level at which carrier off is declared. */
int32_t carrier_off_power;
/*! \brief Current read offset into the equalizer buffer. */
int eq_step;
/*! \brief Current write offset into the equalizer buffer. */
int eq_put_step;
/*! \brief Symbol count to the next equalizer update. */
int eq_skip;
/*! \brief The current half of the baud. */
int baud_half;
/*! \brief The total symbol timing correction since the carrier came up.
This is only for performance analysis purposes. */
int total_baud_timing_correction;
/*! \brief Starting phase angles for the coarse carrier aquisition step. */
int32_t start_angles[2];
/*! \brief History list of phase angles for the coarse carrier aquisition step. */
int32_t angles[16];
/*! \brief A pointer to the current space map. There is a space map for
each trellis state. */
int space_map;
/*! \brief The number of bits in each symbol at the current bit rate. */
int bits_per_symbol;
/*! \brief Current pointer to the trellis buffers */
int trellis_ptr;
/*! \brief The trellis. */
int full_path_to_past_state_locations[V17_TRELLIS_STORAGE_DEPTH][8];
/*! \brief The trellis. */
int past_state_locations[V17_TRELLIS_STORAGE_DEPTH][8];
#if defined(SPANDSP_USE_FIXED_POINTx)
/*! \brief Euclidean distances (actually the squares of the distances)
from the last states of the trellis. */
uint32_t distances[8];
#else
/*! \brief Euclidean distances (actually the squares of the distances)
from the last states of the trellis. */
float distances[8];
#endif
/*! \brief Error and flow logging control */
logging_state_t logging;
};
#endif
/*- End of file ------------------------------------------------------------*/
modem_status_func_t
void(* modem_status_func_t)(void *user_data, int status)
Definition async.h:114
put_bit_func_t
void(* put_bit_func_t)(void *user_data, int bit)
Definition async.h:105
logging_state_t
struct logging_state_s logging_state_t
Definition logging.h:75
complexf_t
Definition complex.h:43
complexi16_t
Definition complex.h:89
power_meter_t
Definition power_meter.h:49
v17_rx_state_s
Definition private/v17rx.h:55
v17_rx_state_s::symbol_sync_low
float symbol_sync_low[2]
Definition private/v17rx.h:135
v17_rx_state_s::qam_report
qam_report_handler_t qam_report
A callback function which may be enabled to report every symbol's constellation position.
Definition private/v17rx.h:70
v17_rx_state_s::carrier_off_power
int32_t carrier_off_power
The power meter level at which carrier off is declared.
Definition private/v17rx.h:196
v17_rx_state_s::eq_coeff
complexf_t eq_coeff[17]
The adaptive equalizer coefficients.
Definition private/v17rx.h:128
v17_rx_state_s::start_angles
int32_t start_angles[2]
Starting phase angles for the coarse carrier aquisition step.
Definition private/v17rx.h:213
v17_rx_state_s::carrier_phase_rate_save
int32_t carrier_phase_rate_save
The carrier update rate saved for reuse when using short training.
Definition private/v17rx.h:189
v17_rx_state_s::space_map
int space_map
A pointer to the current space map. There is a space map for each trellis state.
Definition private/v17rx.h:218
v17_rx_state_s::signal_present
int signal_present
>0 if a signal above the minimum is present. It may or may not be a V.17 signal.
Definition private/v17rx.h:176
v17_rx_state_s::low_samples
int low_samples
A count of the current consecutive samples below the carrier off threshold.
Definition private/v17rx.h:180
v17_rx_state_s::symbol_sync_dc_filter
float symbol_sync_dc_filter[2]
Definition private/v17rx.h:139
v17_rx_state_s::training_error
float training_error
A measure of how much mismatch there is between the real constellation, and the decoded symbol positi...
Definition private/v17rx.h:145
v17_rx_state_s::eq_put_step
int eq_put_step
Current write offset into the equalizer buffer.
Definition private/v17rx.h:201
v17_rx_state_s::logging
logging_state_t logging
Error and flow logging control.
Definition private/v17rx.h:238
v17_rx_state_s::power
power_meter_t power
A power meter, to measure the HPF'ed signal power in the channel.
Definition private/v17rx.h:192
v17_rx_state_s::scramble_reg
uint32_t scramble_reg
The register for the data scrambler.
Definition private/v17rx.h:163
v17_rx_state_s::put_bit
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition private/v17rx.h:59
v17_rx_state_s::trellis_ptr
int trellis_ptr
Current pointer to the trellis buffers.
Definition private/v17rx.h:223
v17_rx_state_s::put_bit_user_data
void * put_bit_user_data
A user specified opaque pointer passed to the put_but routine.
Definition private/v17rx.h:61
v17_rx_state_s::carrier_drop_pending
int carrier_drop_pending
Whether or not a carrier drop was detected and the signal delivery is pending.
Definition private/v17rx.h:178
v17_rx_state_s::carrier_phase
uint32_t carrier_phase
The current phase of the carrier (i.e. the DDS parameter).
Definition private/v17rx.h:185
v17_rx_state_s::short_train
int short_train
Scrambler tap.
Definition private/v17rx.h:168
v17_rx_state_s::training_count
int training_count
A count of how far through the current training step we are.
Definition private/v17rx.h:172
v17_rx_state_s::baud_phase
float baud_phase
Definition private/v17rx.h:141
v17_rx_state_s::distances
float distances[8]
Euclidean distances (actually the squares of the distances) from the last states of the trellis.
Definition private/v17rx.h:235
v17_rx_state_s::rrc_filter_step
int rrc_filter_step
Current offset into the RRC pulse shaping filter buffer.
Definition private/v17rx.h:158
v17_rx_state_s::carrier_phase_rate
int32_t carrier_phase_rate
The update rate for the phase of the carrier (i.e. the DDS increment).
Definition private/v17rx.h:187
v17_rx_state_s::agc_scaling_save
float agc_scaling_save
The previous value of agc_scaling, needed to reuse old training.
Definition private/v17rx.h:123
v17_rx_state_s::diff
int diff
The current state of the differential decoder.
Definition private/v17rx.h:161
v17_rx_state_s::bit_rate
int bit_rate
The bit rate of the modem. Valid values are 7200 9600, 12000 and 14400.
Definition private/v17rx.h:57
v17_rx_state_s::constellation
const complexf_t * constellation
A pointer to the current constellation.
Definition private/v17rx.h:155
v17_rx_state_s::carrier_track_i
float carrier_track_i
The integral part of the carrier tracking filter.
Definition private/v17rx.h:150
v17_rx_state_s::eq_coeff_save
complexf_t eq_coeff_save[17]
A saved set of adaptive equalizer coefficients for use after restarts.
Definition private/v17rx.h:130
v17_rx_state_s::baud_half
int baud_half
The current half of the baud.
Definition private/v17rx.h:206
v17_rx_state_s::carrier_track_p
float carrier_track_p
The proportional part of the carrier tracking filter.
Definition private/v17rx.h:148
v17_rx_state_s::high_sample
int16_t high_sample
A highest magnitude sample seen.
Definition private/v17rx.h:182
v17_rx_state_s::past_state_locations
int past_state_locations[16][8]
The trellis.
Definition private/v17rx.h:227
v17_rx_state_s::symbol_sync_high
float symbol_sync_high[2]
Definition private/v17rx.h:137
v17_rx_state_s::eq_buf
complexf_t eq_buf[17]
The equalizer signal buffer.
Definition private/v17rx.h:132
v17_rx_state_s::rrc_filter
float rrc_filter[27]
The root raised cosine (RRC) pulse shaping filter buffer.
Definition private/v17rx.h:152
v17_rx_state_s::status_handler
modem_status_func_t status_handler
The callback function used to report modem status changes.
Definition private/v17rx.h:64
v17_rx_state_s::total_baud_timing_correction
int total_baud_timing_correction
The total symbol timing correction since the carrier came up. This is only for performance analysis p...
Definition private/v17rx.h:210
v17_rx_state_s::agc_scaling
float agc_scaling
The scaling factor accessed by the AGC algorithm.
Definition private/v17rx.h:121
v17_rx_state_s::eq_step
int eq_step
Current read offset into the equalizer buffer.
Definition private/v17rx.h:199
v17_rx_state_s::carrier_on_power
int32_t carrier_on_power
The power meter level at which carrier on is declared.
Definition private/v17rx.h:194
v17_rx_state_s::full_path_to_past_state_locations
int full_path_to_past_state_locations[16][8]
The trellis.
Definition private/v17rx.h:225
v17_rx_state_s::qam_user_data
void * qam_user_data
A user specified opaque pointer passed to the qam_report callback routine.
Definition private/v17rx.h:73
v17_rx_state_s::eq_skip
int eq_skip
Symbol count to the next equalizer update.
Definition private/v17rx.h:203
v17_rx_state_s::status_user_data
void * status_user_data
A user specified opaque pointer passed to the status function.
Definition private/v17rx.h:66
v17_rx_state_s::last_sample
int16_t last_sample
The value of the last signal sample, using the a simple HPF for signal power estimation.
Definition private/v17rx.h:174
v17_rx_state_s::bits_per_symbol
int bits_per_symbol
The number of bits in each symbol at the current bit rate.
Definition private/v17rx.h:220
v17_rx_state_s::angles
int32_t angles[16]
History list of phase angles for the coarse carrier aquisition step.
Definition private/v17rx.h:215
v17_rx_state_s::training_stage
int training_stage
The section of the training data we are currently in.
Definition private/v17rx.h:170
v17_rx_state_s::eq_delta
float eq_delta
The current delta factor for updating the equalizer coefficients.
Definition private/v17rx.h:126