spandsp  0.0.6
private/v27ter_rx.h
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * private/v27ter_rx.h - ITU V.27ter 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 #if !defined(_SPANDSP_PRIVATE_V27TER_RX_H_)
27 #define _SPANDSP_PRIVATE_V27TER_RX_H_
28 
29 /* Target length for the equalizer is about 43 taps for 4800bps and 32 taps for 2400bps
30  to deal with the worst stuff in V.56bis. */
31 /*! The length of the equalizer buffer. Must be a power of 2 */
32 #define V27TER_EQUALIZER_LEN 32
33 /*! Samples before the target central position in the equalizer buffer */
34 #define V27TER_EQUALIZER_PRE_LEN 16
35 
36 /*! The number of taps in the 4800bps pulse shaping/bandpass filter */
37 #define V27TER_RX_4800_FILTER_STEPS 27
38 /*! The number of taps in the 2400bps pulse shaping/bandpass filter */
39 #define V27TER_RX_2400_FILTER_STEPS 27
40 
41 #if V27TER_RX_4800_FILTER_STEPS > V27TER_RX_2400_FILTER_STEPS
42 #define V27TER_RX_FILTER_STEPS V27TER_RX_4800_FILTER_STEPS
43 #else
44 #define V27TER_RX_FILTER_STEPS V27TER_RX_2400_FILTER_STEPS
45 #endif
46 
47 /*!
48  V.27ter modem receive side descriptor. This defines the working state for a
49  single instance of a V.27ter modem receiver.
50 */
52 {
53  /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
54  int bit_rate;
55  /*! \brief The callback function used to put each bit received. */
57  /*! \brief A user specified opaque pointer passed to the put_bit routine. */
59 
60  /*! \brief The callback function used to report modem status changes. */
62  /*! \brief A user specified opaque pointer passed to the status function. */
64 
65  /*! \brief A callback function which may be enabled to report every symbol's
66  constellation position. */
67  qam_report_handler_t qam_report;
68  /*! \brief A user specified opaque pointer passed to the qam_report callback
69  routine. */
71 
72 #if defined(SPANDSP_USE_FIXED_POINT)
73  /*! \brief The scaling factor assessed by the AGC algorithm. */
74  int16_t agc_scaling;
75  /*! \brief The previous value of agc_scaling, needed to reuse old training. */
76  int16_t agc_scaling_save;
77 
78  /*! \brief The current delta factor for updating the equalizer coefficients. */
79  float eq_delta;
80  /*! \brief The adaptive equalizer coefficients. */
81  /*complexi16_t*/ complexf_t eq_coeff[V27TER_EQUALIZER_LEN];
82  /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
83  /*complexi16_t*/ complexf_t eq_coeff_save[V27TER_EQUALIZER_LEN];
84  /*! \brief The equalizer signal buffer. */
85  /*complexi16_t*/ complexf_t eq_buf[V27TER_EQUALIZER_LEN];
86 
87  /*! \brief A measure of how much mismatch there is between the real constellation,
88  and the decoded symbol positions. */
89  float training_error;
90 
91  /*! \brief The proportional part of the carrier tracking filter. */
92  float carrier_track_p;
93  /*! \brief The integral part of the carrier tracking filter. */
94  float carrier_track_i;
95  /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
96  int16_t rrc_filter[V27TER_RX_FILTER_STEPS];
97 #else
98  /*! \brief The scaling factor assessed by the AGC algorithm. */
99  float agc_scaling;
100  /*! \brief The previous value of agc_scaling, needed to reuse old training. */
102 
103  /*! \brief The current delta factor for updating the equalizer coefficients. */
104  float eq_delta;
105  /*! \brief The adaptive equalizer coefficients. */
106  complexf_t eq_coeff[V27TER_EQUALIZER_LEN];
107  /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
108  complexf_t eq_coeff_save[V27TER_EQUALIZER_LEN];
109  /*! \brief The equalizer signal buffer. */
110  complexf_t eq_buf[V27TER_EQUALIZER_LEN];
111 
112  /*! \brief A measure of how much mismatch there is between the real constellation,
113  and the decoded symbol positions. */
115 
116  /*! \brief The proportional part of the carrier tracking filter. */
118  /*! \brief The integral part of the carrier tracking filter. */
120  /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
121  float rrc_filter[V27TER_RX_FILTER_STEPS];
122 #endif
123  /*! \brief Current offset into the RRC pulse shaping filter buffer. */
125 
126  /*! \brief The register for the training and data scrambler. */
127  uint32_t scramble_reg;
128  /*! \brief A counter for the number of consecutive bits of repeating pattern through
129  the scrambler. */
131  /*! \brief The current step in the table of BC constellation positions. */
133  /*! \brief TRUE if the previous trained values are to be reused. */
135  /*! \brief The section of the training data we are currently in. */
137  /*! \brief A count of how far through the current training step we are. */
139  /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
140  int16_t last_sample;
141  /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.27ter signal. */
143  /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
145  /*! \brief A count of the current consecutive samples below the carrier off threshold. */
147  /*! \brief A highest magnitude sample seen. */
148  int16_t high_sample;
149 
150  /*! \brief The position of the current symbol in the constellation, used for
151  differential decoding. */
153 
154  /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
155  uint32_t carrier_phase;
156  /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
158  /*! \brief The carrier update rate saved for reuse when using short training. */
160 
161  /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */
163  /*! \brief The power meter level at which carrier on is declared. */
165  /*! \brief The power meter level at which carrier off is declared. */
167 
168  /*! \brief Current read offset into the equalizer buffer. */
169  int eq_step;
170  /*! \brief Current write offset into the equalizer buffer. */
172  /*! \brief Symbol counter to the next equalizer update. */
173  int eq_skip;
174 
175  /*! \brief The current half of the baud. */
177 
178  /*! \brief Integration variable for damping the Gardner algorithm tests. */
180  /*! \brief Current step size of Gardner algorithm integration. */
182  /*! \brief The total symbol timing correction since the carrier came up.
183  This is only for performance analysis purposes. */
185 
186  /*! \brief The previous symbol phase angles for the coarse carrier aquisition step. */
187  int32_t last_angles[2];
188  /*! \brief History list of phase angle differences for the coarse carrier aquisition step. */
189  int32_t diff_angles[16];
190 
191  /*! \brief Error and flow logging control */
193 };
194 
195 #endif
196 /*- End of file ------------------------------------------------------------*/
v27ter_rx_state_s::gardner_integrate
int gardner_integrate
Integration variable for damping the Gardner algorithm tests.
Definition: private/v27ter_rx.h:179
dds_advance
void dds_advance(uint32_t *phase_acc, int32_t phase_rate)
Advance the phase, without returning any new signal sample.
Definition: dds_int.c:362
v27ter_rx_state_s::high_sample
int16_t high_sample
A highest magnitude sample seen.
Definition: private/v27ter_rx.h:148
V27TER_TRAINING_SEG_5_LEN
#define V27TER_TRAINING_SEG_5_LEN
Definition: v27ter_rx.c:96
v27ter_rx_set_qam_report_handler
void v27ter_rx_set_qam_report_handler(v27ter_rx_state_t *s, qam_report_handler_t handler, void *user_data)
Definition: v27ter_rx.c:1144
v27ter_rx_state_s::scramble_reg
uint32_t scramble_reg
The register for the training and data scrambler.
Definition: private/v27ter_rx.h:127
v27ter_rx_state_s::eq_skip
int eq_skip
Symbol counter to the next equalizer update.
Definition: private/v27ter_rx.h:173
v27ter_rx_state_s::agc_scaling_save
float agc_scaling_save
The previous value of agc_scaling, needed to reuse old training.
Definition: private/v27ter_rx.h:101
cvec_circular_dot_prodi16
complexi32_t cvec_circular_dot_prodi16(const complexi16_t x[], const complexi16_t y[], int n, int pos)
Find the dot product of two complex int16_t vectors, where the first is a circular buffer with an off...
Definition: complex_vector_int.c:83
modem_status_func_t
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:114
complexf_t
Definition: complex.h:43
SIG_STATUS_CARRIER_UP
@ SIG_STATUS_CARRIER_UP
The carrier signal is up. This merely indicates that carrier energy has been seen....
Definition: async.h:58
V27TER_TRAINING_SEG_3_LEN
#define V27TER_TRAINING_SEG_3_LEN
Definition: v27ter_rx.c:94
dds_advancef
void dds_advancef(uint32_t *phase_acc, int32_t phase_rate)
Advance the phase, without returning any new signal sample.
Definition: dds_float.c:2133
v27ter_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/v27ter_rx.h:140
async.h
power_meter_current_dbm0
float power_meter_current_dbm0(power_meter_t *s)
Get the current power meter reading, in dBm0.
Definition: power_meter.c:120
SIG_STATUS_TRAINING_IN_PROGRESS
@ SIG_STATUS_TRAINING_IN_PROGRESS
The modem is training. This is an early indication that the signal seems to be of the right type....
Definition: async.h:63
v27ter_rx_state_s::logging
logging_state_t logging
Error and flow logging control.
Definition: private/v27ter_rx.h:192
v27ter_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/v27ter_rx.h:157
v27ter_rx_state_s::rrc_filter_step
int rrc_filter_step
Current offset into the RRC pulse shaping filter buffer.
Definition: private/v27ter_rx.h:124
v27ter_rx_state_s::gardner_step
int gardner_step
Current step size of Gardner algorithm integration.
Definition: private/v27ter_rx.h:181
v22bis_state_s::carrier_off_power
int32_t carrier_off_power
The power meter level at which carrier off is declared.
Definition: private/v22bis.h:130
v27ter_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/v27ter_rx.h:184
v27ter_rx_release
int v27ter_rx_release(v27ter_rx_state_t *s)
Release a V.27ter modem receive context.
Definition: v27ter_rx.c:1131
put_bit_func_t
void(* put_bit_func_t)(void *user_data, int bit)
Definition: async.h:105
v22bis_state_s::carrier_on_power
int32_t carrier_on_power
The power meter level at which carrier on is declared.
Definition: private/v22bis.h:128
power_meter_update
int32_t power_meter_update(power_meter_t *s, int16_t amp)
Update a power meter.
Definition: power_meter.c:84
vec_circular_dot_prodf
float vec_circular_dot_prodf(const float x[], const float y[], int n, int pos)
Find the dot product of two float vectors, where the first is a circular buffer with an offset for th...
Definition: vector_float.c:852
v27ter_rx_state_s::agc_scaling
float agc_scaling
The scaling factor assessed by the AGC algorithm.
Definition: private/v27ter_rx.h:99
v27ter_rx_state_s::training_bc
int training_bc
The current step in the table of BC constellation positions.
Definition: private/v27ter_rx.h:132
v27ter_rx_state_s::power
power_meter_t power
A power meter, to measure the HPF'ed signal power in the channel.
Definition: private/v27ter_rx.h:162
SPAN_DECLARE_NONSTD
SPAN_DECLARE_NONSTD(int) async_tx_get_bit(void *user_data)
Get the next bit of a transmitted serial bit stream.
v27ter_rx_state_s::baud_half
int baud_half
The current half of the baud.
Definition: private/v27ter_rx.h:176
v27ter_rx_signal_cutoff
void v27ter_rx_signal_cutoff(v27ter_rx_state_t *s, float cutoff)
Definition: v27ter_rx.c:158
v27ter_rx_state_s::eq_delta
float eq_delta
The current delta factor for updating the equalizer coefficients.
Definition: private/v27ter_rx.h:104
v27ter_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/v27ter_rx.h:144
v27ter_rx_state_s::rrc_filter
float rrc_filter[27]
The root raised cosine (RRC) pulse shaping filter buffer.
Definition: private/v27ter_rx.h:121
power_meter_t
Definition: power_meter.h:49
v27ter_rx_state_s::eq_put_step
int eq_put_step
Current write offset into the equalizer buffer.
Definition: private/v27ter_rx.h:171
complex.h
complexf_t::im
float im
Imaginary part.
Definition: complex.h:47
dds_phase_to_radians
float dds_phase_to_radians(uint32_t phase)
Convert a 32 bit phase angle to an angle in radians, between 0 and 2*PI.
Definition: dds_float.c:2103
v27ter_rx_state_s::carrier_track_i
float carrier_track_i
The integral part of the carrier tracking filter.
Definition: private/v27ter_rx.h:119
v27ter_rx_state_s::low_samples
int low_samples
A count of the current consecutive samples below the carrier off threshold.
Definition: private/v27ter_rx.h:146
CARRIER_NOMINAL_FREQ
#define CARRIER_NOMINAL_FREQ
Definition: v27ter_rx.c:77
v27ter_rx_state_s::put_bit_user_data
void * put_bit_user_data
A user specified opaque pointer passed to the put_bit routine.
Definition: private/v27ter_rx.h:58
EQUALIZER_DELTA
#define EQUALIZER_DELTA
Definition: v27ter_rx.c:83
dds_lookup_complexi16
complexi16_t dds_lookup_complexi16(uint32_t phase)
Generate a complex 16 bit integer tone sample.
Definition: dds_int.c:415
v27ter_rx_state_s::bit_rate
int bit_rate
The bit rate of the modem. Valid values are 2400 and 4800.
Definition: private/v27ter_rx.h:54
v27ter_rx.h
SIG_STATUS_TRAINING_FAILED
@ SIG_STATUS_TRAINING_FAILED
The modem has failed to train.
Definition: async.h:67
v22bis_state_s::bit_rate
int bit_rate
The maximum permitted bit rate of the modem. Valid values are 1200 and 2400.
Definition: private/v22bis.h:75
complexi32_t
Definition: complex.h:100
v22bis_state_s::put_bit
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition: private/v22bis.h:83
v27ter_rx_signal_power
float v27ter_rx_signal_power(v27ter_rx_state_t *s)
Definition: v27ter_rx.c:152
SIG_STATUS_CARRIER_DOWN
@ SIG_STATUS_CARRIER_DOWN
The carrier signal has dropped.
Definition: async.h:54
dds_lookup_complexf
complexf_t dds_lookup_complexf(uint32_t phase)
Lookup the complex value of a specified phase.
Definition: dds_float.c:2176
complexi32_t::im
int32_t im
Imaginary part.
Definition: complex.h:104
v27ter_rx_state_s::qam_user_data
void * qam_user_data
A user specified opaque pointer passed to the qam_report callback routine.
Definition: private/v27ter_rx.h:70
complexi32_t::re
int32_t re
Real part.
Definition: complex.h:102
vec_circular_dot_prodi16
int32_t vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos)
Find the dot product of two int16_t vectors, where the first is a circular buffer with an offset for ...
Definition: vector_int.c:261
v27ter_rx_free
int v27ter_rx_free(v27ter_rx_state_t *s)
Free a V.27ter modem receive context.
Definition: v27ter_rx.c:1137
cvec_circular_dot_prodf
complexf_t cvec_circular_dot_prodf(const complexf_t x[], const complexf_t y[], int n, int pos)
Find the dot product of two complex float vectors, where the first is a circular buffer with an offse...
Definition: complex_vector_float.c:173
v27ter_rx_state_s::carrier_off_power
int32_t carrier_off_power
The power meter level at which carrier off is declared.
Definition: private/v27ter_rx.h:166
v27ter_rx_state_s::status_user_data
void * status_user_data
A user specified opaque pointer passed to the status function.
Definition: private/v27ter_rx.h:63
v27ter_rx_state_s::constellation_state
int constellation_state
The position of the current symbol in the constellation, used for differential decoding.
Definition: private/v27ter_rx.h:152
complexi16_t
Definition: complex.h:89
span_log
int span_log(logging_state_t *s, int level, const char *format,...)
Generate a log entry.
Definition: logging.c:84
v27ter_rx_state_s
Definition: private/v27ter_rx.h:52
v27ter_rx_state_s::eq_coeff
complexf_t eq_coeff[32]
The adaptive equalizer coefficients.
Definition: private/v27ter_rx.h:106
v29rx.h
v27ter_rx_state_s::last_angles
int32_t last_angles[2]
The previous symbol phase angles for the coarse carrier aquisition step.
Definition: private/v27ter_rx.h:187
dds_frequencyf
float dds_frequencyf(int32_t phase_rate)
Find the frequency, in Hz, equivalent to a phase rate.
Definition: dds_float.c:2115
v27ter_rx_state_s::diff_angles
int32_t diff_angles[16]
History list of phase angle differences for the coarse carrier aquisition step.
Definition: private/v27ter_rx.h:189
complexi16_t::im
int16_t im
Imaginary part.
Definition: complex.h:93
v27ter_rx_set_put_bit
void v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t put_bit, void *user_data)
Change the put_bit function associated with a V.27ter modem receive context.
Definition: v27ter_rx.c:1016
v27ter_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/v27ter_rx.h:114
v22bis_state_s::constellation_state
int constellation_state
The code number for the current position in the constellation.
Definition: private/v22bis.h:132
v27ter_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.27ter signal.
Definition: private/v27ter_rx.h:142
V27TER_TRAINING_SEG_6_LEN
#define V27TER_TRAINING_SEG_6_LEN
Definition: v27ter_rx.c:98
v27ter_rx_state_s::carrier_phase
uint32_t carrier_phase
The current phase of the carrier (i.e. the DDS parameter).
Definition: private/v27ter_rx.h:155
power_meter_level_dbm0
int32_t power_meter_level_dbm0(float level)
Get the current power meter reading, in dBm0.
Definition: power_meter.c:91
v27ter_rx_state_s::put_bit
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition: private/v27ter_rx.h:56
v27ter_rx_state_s::eq_coeff_save
complexf_t eq_coeff_save[32]
A saved set of adaptive equalizer coefficients for use after restarts.
Definition: private/v27ter_rx.h:108
v27ter_rx_state_s::training_stage
int training_stage
The section of the training data we are currently in.
Definition: private/v27ter_rx.h:136
logging.h
v27ter_rx_get_logging_state
logging_state_t * v27ter_rx_get_logging_state(v27ter_rx_state_t *s)
Get the logging context associated with a V.27ter modem receive context.
Definition: v27ter_rx.c:1030
v27ter_rx_restart
int v27ter_rx_restart(v27ter_rx_state_t *s, int bit_rate, int old_train)
Reinitialise an existing V.27ter modem receive context.
Definition: v27ter_rx.c:1036
v27ter_rx_state_s::eq_buf
complexf_t eq_buf[32]
The equalizer signal buffer.
Definition: private/v27ter_rx.h:110
v27ter_rx_state_s::carrier_on_power
int32_t carrier_on_power
The power meter level at which carrier on is declared.
Definition: private/v27ter_rx.h:164
v27ter_rx_state_s::eq_step
int eq_step
Current read offset into the equalizer buffer.
Definition: private/v27ter_rx.h:169
complexf_t::re
float re
Real part.
Definition: complex.h:45
v27ter_rx_state_s::scrambler_pattern_count
int scrambler_pattern_count
A counter for the number of consecutive bits of repeating pattern through the scrambler.
Definition: private/v27ter_rx.h:130
v27ter_rx_symbol_timing_correction
float v27ter_rx_symbol_timing_correction(v27ter_rx_state_t *s)
Definition: v27ter_rx.c:143
v27ter_rx_state_s::carrier_track_p
float carrier_track_p
The proportional part of the carrier tracking filter.
Definition: private/v27ter_rx.h:117
v27ter_rx_state_s::training_count
int training_count
A count of how far through the current training step we are.
Definition: private/v27ter_rx.h:138
complexi16_t::re
int16_t re
Real part.
Definition: complex.h:91
arctan2.h
v27ter_rx_init
v27ter_rx_state_t * v27ter_rx_init(v27ter_rx_state_t *s, int bit_rate, put_bit_func_t put_bit, void *user_data)
Initialise a V.27ter modem receive context.
Definition: v27ter_rx.c:1104
power_meter_init
power_meter_t * power_meter_init(power_meter_t *s, int shift)
Initialise a power meter context.
Definition: power_meter.c:50
SIG_STATUS_TRAINING_SUCCEEDED
@ SIG_STATUS_TRAINING_SUCCEEDED
The modem has trained, and is ready for data exchange.
Definition: async.h:65
v27ter_rx_set_modem_status_handler
void v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_status_func_t handler, void *user_data)
Change the modem status report function associated with a V.27ter modem receive context.
Definition: v27ter_rx.c:1023
v27ter_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/v27ter_rx.h:159
v27ter_rx_state_s::status_handler
modem_status_func_t status_handler
The callback function used to report modem status changes.
Definition: private/v27ter_rx.h:61
v27ter_rx_carrier_frequency
float v27ter_rx_carrier_frequency(v27ter_rx_state_t *s)
Definition: v27ter_rx.c:137
logging_state_s
Definition: private/logging.h:34
v27ter_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/v27ter_rx.h:67
v27ter_rx_state_s::old_train
int old_train
TRUE if the previous trained values are to be reused.
Definition: private/v27ter_rx.h:134
v27ter_rx_equalizer_state
int v27ter_rx_equalizer_state(v27ter_rx_state_t *s, complexf_t **coeffs)
Get a snapshot of the current equalizer coefficients.
Definition: v27ter_rx.c:178
dds.h