From 04e93f4c0b4be6bd4e1f7613eb4480ee3a952c6a Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Sun, 5 Aug 2012 22:20:39 +0800 Subject: [PATCH] Fix fixed point builds of spandsp, and improve logging of modem performance during tests --- libs/spandsp/src/spandsp/v17rx.h | 6 ++ libs/spandsp/src/spandsp/v22bis.h | 6 ++ libs/spandsp/src/spandsp/v27ter_rx.h | 6 ++ libs/spandsp/src/spandsp/v29rx.h | 6 ++ libs/spandsp/src/v17rx.c | 3 +- libs/spandsp/tests/modem_monitor.cpp | 32 ++++--- libs/spandsp/tests/modem_monitor.h | 2 +- libs/spandsp/tests/v17_tests.c | 73 +++++++-------- libs/spandsp/tests/v22bis_tests.c | 66 +++++++------ libs/spandsp/tests/v27ter_tests.c | 133 ++++++++++++--------------- libs/spandsp/tests/v29_tests.c | 71 +++++++------- 11 files changed, 197 insertions(+), 207 deletions(-) diff --git a/libs/spandsp/src/spandsp/v17rx.h b/libs/spandsp/src/spandsp/v17rx.h index 892217889a..935d542853 100644 --- a/libs/spandsp/src/spandsp/v17rx.h +++ b/libs/spandsp/src/spandsp/v17rx.h @@ -209,6 +209,12 @@ working only on the most optimal lines, and being widely usable across most phon TCM absolutely transformed the phone line modem business. */ +#if defined(SPANDSP_USE_FIXED_POINT) +#define V17_CONSTELLATION_SCALING_FACTOR 1024.0 +#else +#define V17_CONSTELLATION_SCALING_FACTOR 1.0 +#endif + /*! V.17 modem receive side descriptor. This defines the working state for a single instance of a V.17 modem receiver. diff --git a/libs/spandsp/src/spandsp/v22bis.h b/libs/spandsp/src/spandsp/v22bis.h index 440118c7cb..6361c05841 100644 --- a/libs/spandsp/src/spandsp/v22bis.h +++ b/libs/spandsp/src/spandsp/v22bis.h @@ -48,6 +48,12 @@ or 1200bps if one or both ends to not acknowledge that 2400bps is OK. #if !defined(_SPANDSP_V22BIS_H_) #define _SPANDSP_V22BIS_H_ +#if defined(SPANDSP_USE_FIXED_POINT) +#define V22BIS_CONSTELLATION_SCALING_FACTOR 1024.0 +#else +#define V22BIS_CONSTELLATION_SCALING_FACTOR 1.0 +#endif + enum { V22BIS_GUARD_TONE_NONE, diff --git a/libs/spandsp/src/spandsp/v27ter_rx.h b/libs/spandsp/src/spandsp/v27ter_rx.h index 6b464b3d42..a6055844d6 100644 --- a/libs/spandsp/src/spandsp/v27ter_rx.h +++ b/libs/spandsp/src/spandsp/v27ter_rx.h @@ -44,6 +44,12 @@ at the start of transmission, which makes the design of a V.27ter receiver relat straightforward. */ +#if defined(SPANDSP_USE_FIXED_POINT) +#define V27TER_CONSTELLATION_SCALING_FACTOR 1024.0 +#else +#define V27TER_CONSTELLATION_SCALING_FACTOR 1.0 +#endif + /*! V.27ter modem receive side descriptor. This defines the working state for a single instance of a V.27ter modem receiver. diff --git a/libs/spandsp/src/spandsp/v29rx.h b/libs/spandsp/src/spandsp/v29rx.h index bdcd23f944..bb52e624dc 100644 --- a/libs/spandsp/src/spandsp/v29rx.h +++ b/libs/spandsp/src/spandsp/v29rx.h @@ -118,6 +118,12 @@ scrambler register) cannot be trusted for the test. The receive modem, therefore, only tests that bits starting at bit 24 are really ones. */ +#if defined(SPANDSP_USE_FIXED_POINT) +#define V29_CONSTELLATION_SCALING_FACTOR 4096.0 +#else +#define V29_CONSTELLATION_SCALING_FACTOR 1.0 +#endif + #if defined(SPANDSP_USE_FIXED_POINT) typedef void (*qam_report_handler_t)(void *user_data, const complexi16_t *constel, const complexi16_t *target, int symbol); #else diff --git a/libs/spandsp/src/v17rx.c b/libs/spandsp/src/v17rx.c index 27c568c46a..9d692a1548 100644 --- a/libs/spandsp/src/v17rx.c +++ b/libs/spandsp/src/v17rx.c @@ -202,10 +202,11 @@ SPAN_DECLARE(int) v17_rx_equalizer_state(v17_rx_state_t *s, complexf_t **coeffs) { #if defined(SPANDSP_USE_FIXED_POINT) *coeffs = NULL; + return 0; #else *coeffs = s->eq_coeff; -#endif return V17_EQUALIZER_LEN; +#endif } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/tests/modem_monitor.cpp b/libs/spandsp/tests/modem_monitor.cpp index a5ba73289f..db8a31a22d 100644 --- a/libs/spandsp/tests/modem_monitor.cpp +++ b/libs/spandsp/tests/modem_monitor.cpp @@ -52,10 +52,10 @@ #define SYMBOL_TRACKER_POINTS 12000 #define CARRIER_TRACKER_POINTS 12000 -#define FP_FACTOR 4096 - struct qam_monitor_s { + float constel_scaling; + Fl_Double_Window *w; Fl_Group *c_const; Fl_Group *c_right; @@ -189,14 +189,14 @@ int qam_monitor_update_equalizer(qam_monitor_t *s, const complexf_t *coeffs, int for (i = 0; i < len; i++) { s->eq_re_plot[2*i] = (i - len/2)/2.0; - s->eq_re_plot[2*i + 1] = coeffs[i].re; + s->eq_re_plot[2*i + 1] = coeffs[i].re*s->constel_scaling; if (min > coeffs[i].re) min = coeffs[i].re; if (max < coeffs[i].re) max = coeffs[i].re; s->eq_im_plot[2*i] = (i - len/2)/2.0; - s->eq_im_plot[2*i + 1] = coeffs[i].im; + s->eq_im_plot[2*i + 1] = coeffs[i].im*s->constel_scaling; if (min > coeffs[i].im) min = coeffs[i].im; if (max < coeffs[i].im) @@ -235,22 +235,22 @@ int qam_monitor_update_int_equalizer(qam_monitor_t *s, const complexi16_t *coeff max = coeffs[i].im; for (i = 0; i < len; i++) { - s->eq_re_plot[2*i] = (i - len/2)/2.0f; - s->eq_re_plot[2*i + 1] = coeffs[i].re/(float) FP_FACTOR; if (min > coeffs[i].re) min = coeffs[i].re; if (max < coeffs[i].re) max = coeffs[i].re; + s->eq_re_plot[2*i] = (i - len/2)/2.0f; + s->eq_re_plot[2*i + 1] = coeffs[i].re*s->constel_scaling; - s->eq_im_plot[2*i] = (i - len/2)/2.0f; - s->eq_im_plot[2*i + 1] = coeffs[i].im/(float) FP_FACTOR; if (min > coeffs[i].im) min = coeffs[i].im; if (max < coeffs[i].im) max = coeffs[i].im; + s->eq_im_plot[2*i] = (i - len/2)/2.0f; + s->eq_im_plot[2*i + 1] = coeffs[i].im*s->constel_scaling; } - min /= (float) FP_FACTOR; - max /= (float) FP_FACTOR; + min *= s->constel_scaling; + max *= s->constel_scaling; s->eq_x->minimum(-len/4.0); s->eq_x->maximum(len/4.0); @@ -286,21 +286,21 @@ int qam_monitor_update_symbol_tracking(qam_monitor_t *s, float total_correction) max = s->symbol_tracker[0]; for (i = s->symbol_track_ptr, j = 0; i < s->symbol_track_points; i++, j++) { - s->symbol_track_plot[2*j] = j; - s->symbol_track_plot[2*j + 1] = s->symbol_tracker[i]; if (min > s->symbol_tracker[i]) min = s->symbol_tracker[i]; if (max < s->symbol_tracker[i]) max = s->symbol_tracker[i]; + s->symbol_track_plot[2*j] = j; + s->symbol_track_plot[2*j + 1] = s->symbol_tracker[i]; } for (i = 0; i < s->symbol_track_ptr; i++, j++) { - s->symbol_track_plot[2*j] = j; - s->symbol_track_plot[2*j + 1] = s->symbol_tracker[i]; if (min > s->symbol_tracker[i]) min = s->symbol_tracker[i]; if (max < s->symbol_tracker[i]) max = s->symbol_tracker[i]; + s->symbol_track_plot[2*j] = j; + s->symbol_track_plot[2*j + 1] = s->symbol_tracker[i]; } s->symbol_track_y->maximum((fabs(max - min) < 0.05) ? max + 0.05 : max); s->symbol_track_y->minimum(min); @@ -379,7 +379,7 @@ int qam_monitor_update_carrier_tracking(qam_monitor_t *s, float carrier_freq) } /*- End of function --------------------------------------------------------*/ -qam_monitor_t *qam_monitor_init(float constel_width, const char *tag) +qam_monitor_t *qam_monitor_init(float constel_width, float constel_scaling, const char *tag) { char buf[132 + 1]; float x; @@ -391,6 +391,8 @@ qam_monitor_t *qam_monitor_init(float constel_width, const char *tag) s->w = new Fl_Double_Window(905, 400, (tag) ? tag : "QAM monitor"); + s->constel_scaling = 1.0/constel_scaling; + s->c_const = new Fl_Group(0, 0, 380, 400); s->c_const->box(FL_DOWN_BOX); s->c_const->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE); diff --git a/libs/spandsp/tests/modem_monitor.h b/libs/spandsp/tests/modem_monitor.h index b1b79fda06..3a3f896b8a 100644 --- a/libs/spandsp/tests/modem_monitor.h +++ b/libs/spandsp/tests/modem_monitor.h @@ -50,7 +50,7 @@ extern "C" { #endif -qam_monitor_t *qam_monitor_init(float constel_width, const char *tag); +qam_monitor_t *qam_monitor_init(float constel_width, float constel_scaling, const char *tag); int qam_monitor_clear_constel(qam_monitor_t *s); int qam_monitor_update_constel(qam_monitor_t *s, const complexf_t *pt); int qam_monitor_update_equalizer(qam_monitor_t *s, const complexf_t *coeffs, int len); diff --git a/libs/spandsp/tests/v17_tests.c b/libs/spandsp/tests/v17_tests.c index a974049a29..39b5a4a319 100644 --- a/libs/spandsp/tests/v17_tests.c +++ b/libs/spandsp/tests/v17_tests.c @@ -133,14 +133,17 @@ static void v17_rx_status(void *user_data, int status) switch (status) { case SIG_STATUS_TRAINING_SUCCEEDED: - len = v17_rx_equalizer_state(s, &coeffs); - printf("Equalizer:\n"); - for (i = 0; i < len; i++) + printf("Training succeeded\n"); + if ((len = v17_rx_equalizer_state(s, &coeffs))) + { + printf("Equalizer:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/4096.0f, coeffs[i].im/4096.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V17_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V17_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + } break; } } @@ -183,10 +186,11 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex int len; #if defined(SPANDSP_USE_FIXED_POINT) complexi16_t *coeffs; - complexf_t constel_point; #else complexf_t *coeffs; #endif + complexf_t constel_point; + complexf_t target_point; float fpower; v17_rx_state_t *rx; static float smooth_power = 0.0f; @@ -195,67 +199,56 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex rx = (v17_rx_state_t *) user_data; if (constel) { - fpower = (constel->re - target->re)*(constel->re - target->re) - + (constel->im - target->im)*(constel->im - target->im); -#if defined(SPANDSP_USE_FIXED_POINT) - fpower /= 4096.0*4096.0; -#endif + constel_point.re = constel->re/V17_CONSTELLATION_SCALING_FACTOR; + constel_point.im = constel->im/V17_CONSTELLATION_SCALING_FACTOR; + target_point.re = target->re/V17_CONSTELLATION_SCALING_FACTOR, + target_point.im = target->im/V17_CONSTELLATION_SCALING_FACTOR, + fpower = (constel_point.re - target_point.re)*(constel_point.re - target_point.re) + + (constel_point.im - target_point.im)*(constel_point.im - target_point.im); smooth_power = 0.95f*smooth_power + 0.05f*fpower; #if defined(ENABLE_GUI) if (use_gui) { -#if defined(SPANDSP_USE_FIXED_POINT) - constel_point.re = constel->re/4096.0; - constel_point.im = constel->im/4096.0; qam_monitor_update_constel(qam_monitor, &constel_point); -#else - qam_monitor_update_constel(qam_monitor, constel); -#endif qam_monitor_update_carrier_tracking(qam_monitor, v17_rx_carrier_frequency(rx)); qam_monitor_update_symbol_tracking(qam_monitor, v17_rx_symbol_timing_correction(rx)); } #endif printf("%8d [%8.4f, %8.4f] [%8.4f, %8.4f] %2x %8.4f %8.4f %9.4f %7.3f %7.4f\n", symbol_no, -#if defined(SPANDSP_USE_FIXED_POINT) - constel->re/4096.0, - constel->im/4096.0, - target->re/4096.0, - target->im/4096.0, -#else - constel->re, - constel->im, - target->re, - target->im, -#endif + constel_point.re, + constel_point.im, + target_point.re, + target_point.im, symbol, fpower, smooth_power, v17_rx_carrier_frequency(rx), v17_rx_signal_power(rx), v17_rx_symbol_timing_correction(rx)); - //printf("Carrier %d %f %f\n", symbol_no, v17_rx_carrier_frequency(rx), v17_rx_symbol_timing_correction(rx)); symbol_no++; if (--update_interval <= 0) { - len = v17_rx_equalizer_state(rx, &coeffs); - printf("Equalizer A:\n"); - for (i = 0; i < len; i++) + if ((len = v17_rx_equalizer_state(rx, &coeffs))) + { + printf("Equalizer A:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/4096.0f, coeffs[i].im/4096.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V17_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V17_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif #if defined(ENABLE_GUI) - if (use_gui) - { + if (use_gui) + { #if defined(SPANDSP_USE_FIXED_POINT) - qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); + qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); #else - qam_monitor_update_equalizer(qam_monitor, coeffs, len); + qam_monitor_update_equalizer(qam_monitor, coeffs, len); +#endif + } #endif } -#endif update_interval = 100; } } @@ -481,7 +474,7 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) { - qam_monitor = qam_monitor_init(10.0f, NULL); + qam_monitor = qam_monitor_init(10.0f, V17_CONSTELLATION_SCALING_FACTOR, NULL); if (!decode_test_file) { start_line_model_monitor(129); diff --git a/libs/spandsp/tests/v22bis_tests.c b/libs/spandsp/tests/v22bis_tests.c index 23515f4038..f9604554d0 100644 --- a/libs/spandsp/tests/v22bis_tests.c +++ b/libs/spandsp/tests/v22bis_tests.c @@ -129,14 +129,16 @@ static void v22bis_rx_status(void *user_data, int status) case SIG_STATUS_TRAINING_SUCCEEDED: bit_rate = v22bis_get_current_bit_rate(s->v22bis); printf("Negotiated bit rate: %d\n", bit_rate); - len = v22bis_rx_equalizer_state(s->v22bis, &coeffs); - printf("Equalizer:\n"); - for (i = 0; i < len; i++) + if ((len = v22bis_rx_equalizer_state(s->v22bis, &coeffs))) + { + printf("Equalizer:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/1024.0f, coeffs[i].im/1024.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V22BIS_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V22BIS_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + } break; } } @@ -181,26 +183,25 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex int len; #if defined(SPANDSP_USE_FIXED_POINT) complexi16_t *coeffs; - complexf_t constel_point; #else complexf_t *coeffs; #endif + complexf_t constel_point; + complexf_t target_point; float fpower; endpoint_t *s; s = (endpoint_t *) user_data; if (constel) { + constel_point.re = constel->re/V22BIS_CONSTELLATION_SCALING_FACTOR; + constel_point.im = constel->im/V22BIS_CONSTELLATION_SCALING_FACTOR; + target_point.re = target->re/V22BIS_CONSTELLATION_SCALING_FACTOR; + target_point.im = target->im/V22BIS_CONSTELLATION_SCALING_FACTOR; #if defined(ENABLE_GUI) if (use_gui) { -#if defined(SPANDSP_USE_FIXED_POINT) - constel_point.re = constel->re/1024.0; - constel_point.im = constel->im/1024.0; qam_monitor_update_constel(s->qam_monitor, &constel_point); -#else - qam_monitor_update_constel(s->qam_monitor, constel); -#endif qam_monitor_update_carrier_tracking(s->qam_monitor, v22bis_rx_carrier_frequency(s->v22bis)); qam_monitor_update_symbol_tracking(s->qam_monitor, v22bis_rx_symbol_timing_correction(s->v22bis)); } @@ -211,17 +212,10 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex printf("%8d [%8.4f, %8.4f] [%8.4f, %8.4f] %2x %8.4f %8.4f %8.4f\n", s->symbol_no, -#if defined(SPANDSP_USE_FIXED_POINT) - constel->re/1024.0, - constel->im/1024.0, - target->re/1024.0, - target->im/1024.0, -#else - constel->re, - constel->im, - target->re, - target->im, -#endif + constel_point.re, + constel_point.im, + target_point.re, + target_point.im, symbol, fpower, s->smooth_power, @@ -231,24 +225,26 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex else { printf("Gardner step %d\n", symbol); - len = v22bis_rx_equalizer_state(s->v22bis, &coeffs); - printf("Equalizer A:\n"); - for (i = 0; i < len; i++) + if ((len = v22bis_rx_equalizer_state(s->v22bis, &coeffs))) + { + printf("Equalizer A:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/1024.0f, coeffs[i].im/1024.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V22BIS_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V22BIS_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif #if defined(ENABLE_GUI) - if (use_gui) - { + if (use_gui) + { #if defined(SPANDSP_USE_FIXED_POINT) - qam_monitor_update_int_equalizer(s->qam_monitor, coeffs, len); + qam_monitor_update_int_equalizer(s->qam_monitor, coeffs, len); #else - qam_monitor_update_equalizer(s->qam_monitor, coeffs, len); + qam_monitor_update_equalizer(s->qam_monitor, coeffs, len); +#endif + } #endif } -#endif } } /*- End of function --------------------------------------------------------*/ @@ -381,8 +377,8 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) { - endpoint[0].qam_monitor = qam_monitor_init(6.0f, "Calling modem"); - endpoint[1].qam_monitor = qam_monitor_init(6.0f, "Answering modem"); + endpoint[0].qam_monitor = qam_monitor_init(6.0f, V22BIS_CONSTELLATION_SCALING_FACTOR, "Calling modem"); + endpoint[1].qam_monitor = qam_monitor_init(6.0f, V22BIS_CONSTELLATION_SCALING_FACTOR, "Answering modem"); } #endif if ((model = both_ways_line_model_init(line_model_no, diff --git a/libs/spandsp/tests/v27ter_tests.c b/libs/spandsp/tests/v27ter_tests.c index 0d63023cc0..db5a13d29f 100644 --- a/libs/spandsp/tests/v27ter_tests.c +++ b/libs/spandsp/tests/v27ter_tests.c @@ -129,14 +129,16 @@ static void v27ter_rx_status(void *user_data, int status) switch (status) { case SIG_STATUS_TRAINING_SUCCEEDED: - len = v27ter_rx_equalizer_state(s, &coeffs); - printf("Equalizer:\n"); - for (i = 0; i < len; i++) + if ((len = v27ter_rx_equalizer_state(s, &coeffs))) + { + printf("Equalizer:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/4096.0f, coeffs[i].im/4096.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V27TER_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V27TER_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + } break; } } @@ -179,115 +181,94 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex int len; #if defined(SPANDSP_USE_FIXED_POINT) complexi16_t *coeffs; - complexf_t constel_point; #else complexf_t *coeffs; #endif + complexf_t constel_point; + complexf_t target_point; float fpower; float error; v27ter_rx_state_t *rx; static float smooth_power = 0.0f; -#if defined(ENABLE_GUI) - static int reports = 0; -#endif + static int update_interval = 100; rx = (v27ter_rx_state_t *) user_data; if (constel) { - fpower = (constel->re - target->re)*(constel->re - target->re) - + (constel->im - target->im)*(constel->im - target->im); -#if defined(SPANDSP_USE_FIXED_POINT) - fpower /= 1024.0*1024.0; -#endif + constel_point.re = constel->re/V27TER_CONSTELLATION_SCALING_FACTOR; + constel_point.im = constel->im/V27TER_CONSTELLATION_SCALING_FACTOR; + target_point.re = target->re/V27TER_CONSTELLATION_SCALING_FACTOR; + target_point.im = target->im/V27TER_CONSTELLATION_SCALING_FACTOR; + fpower = (constel_point.re - target_point.re)*(constel_point.re - target_point.re) + + (constel_point.im - target_point.im)*(constel_point.im - target_point.im); smooth_power = 0.95f*smooth_power + 0.05f*fpower; #if defined(ENABLE_GUI) if (use_gui) { -#if defined(SPANDSP_USE_FIXED_POINT) - constel_point.re = constel->re/1024.0; - constel_point.im = constel->im/1024.0; qam_monitor_update_constel(qam_monitor, &constel_point); -#else - qam_monitor_update_constel(qam_monitor, constel); -#endif qam_monitor_update_carrier_tracking(qam_monitor, v27ter_rx_carrier_frequency(rx)); qam_monitor_update_symbol_tracking(qam_monitor, v27ter_rx_symbol_timing_correction(rx)); } #endif error = constel->im*target->re - constel->re*target->im; -#if defined(SPANDSP_USE_FIXED_POINT) - printf("Tracking error %f %f %f %f %f %f\n", error, v27ter_rx_carrier_frequency(rx), constel->re/1024.0, constel->im/1024.0, target->re/1024.0, target->im/1024.0); -#else - printf("Tracking error %f %f %f %f %f %f\n", error, v27ter_rx_carrier_frequency(rx), constel->re, constel->im, target->re, target->im); -#endif + printf("Tracking error %f %f %f %f %f %f\n", error, v27ter_rx_carrier_frequency(rx), constel_point.re, constel_point.im, target_point.re, target_point.im); printf("%8d [%8.4f, %8.4f] [%8.4f, %8.4f] %2x %8.4f %8.4f %9.4f %7.3f %7.4f\n", symbol_no, -#if defined(SPANDSP_USE_FIXED_POINT) - constel->re/1024.0, - constel->im/1024.0, - target->re/1024.0, - target->im/1024.0, -#else - constel->re, - constel->im, - target->re, - target->im, -#endif + constel_point.re, + constel_point.im, + target_point.re, + target_point.im, symbol, fpower, smooth_power, v27ter_rx_carrier_frequency(rx), v27ter_rx_signal_power(rx), v27ter_rx_symbol_timing_correction(rx)); - len = v27ter_rx_equalizer_state(rx, &coeffs); - printf("Equalizer B:\n"); - for (i = 0; i < len; i++) -#if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/1024.0f, coeffs[i].im/1024.0f); -#else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); -#endif -#if defined(WITH_SPANDSP_INTERNALS) - printf("Gardtest %d %f %d\n", symbol_no, v27ter_rx_symbol_timing_correction(rx), rx->gardner_integrate); -#endif - printf("Carcar %d %f\n", symbol_no, v27ter_rx_carrier_frequency(rx)); -#if defined(ENABLE_GUI) - if (use_gui) + symbol_no++; + if (--update_interval <= 0) { - if (++reports >= 1000) + if ((len = v27ter_rx_equalizer_state(rx, &coeffs))) + { + printf("Equalizer B:\n"); + for (i = 0; i < len; i++) + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V27TER_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V27TER_CONSTELLATION_SCALING_FACTOR); +#if defined(ENABLE_GUI) + if (use_gui) + { +#if defined(SPANDSP_USE_FIXED_POINT) + qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); +#else + qam_monitor_update_equalizer(qam_monitor, coeffs, len); +#endif + } + } + update_interval = 100; + } +#endif + } + else + { + printf("Gardner step %d\n", symbol); + if ((len = v27ter_rx_equalizer_state(rx, &coeffs))) + { + printf("Equalizer A:\n"); + for (i = 0; i < len; i++) +#if defined(SPANDSP_USE_FIXED_POINT) + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V27TER_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V27TER_CONSTELLATION_SCALING_FACTOR); +#else + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); +#endif +#if defined(ENABLE_GUI) + if (use_gui) { #if defined(SPANDSP_USE_FIXED_POINT) qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); #else qam_monitor_update_equalizer(qam_monitor, coeffs, len); #endif - reports = 0; } - } -#endif - symbol_no++; - } - else - { - printf("Gardner step %d\n", symbol); - len = v27ter_rx_equalizer_state(rx, &coeffs); - printf("Equalizer A:\n"); - for (i = 0; i < len; i++) -#if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/1024.0f, coeffs[i].im/1024.0f); -#else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); -#endif -#if defined(ENABLE_GUI) - if (use_gui) - { -#if defined(SPANDSP_USE_FIXED_POINT) - qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); -#else - qam_monitor_update_equalizer(qam_monitor, coeffs, len); #endif } -#endif } } /*- End of function --------------------------------------------------------*/ @@ -497,7 +478,7 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) { - qam_monitor = qam_monitor_init(2.0f, NULL); + qam_monitor = qam_monitor_init(2.0f, V27TER_CONSTELLATION_SCALING_FACTOR, NULL); if (!decode_test_file) { start_line_model_monitor(129); diff --git a/libs/spandsp/tests/v29_tests.c b/libs/spandsp/tests/v29_tests.c index 1252a4fc4b..c7335b08ec 100644 --- a/libs/spandsp/tests/v29_tests.c +++ b/libs/spandsp/tests/v29_tests.c @@ -129,14 +129,16 @@ static void v29_rx_status(void *user_data, int status) { case SIG_STATUS_TRAINING_SUCCEEDED: printf("Training succeeded\n"); - len = v29_rx_equalizer_state(s, &coeffs); - printf("Equalizer:\n"); - for (i = 0; i < len; i++) + if ((len = v29_rx_equalizer_state(s, &coeffs))) + { + printf("Equalizer:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/4096.0f, coeffs[i].im/4096.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V29_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V29_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + } break; } } @@ -179,10 +181,11 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex int len; #if defined(SPANDSP_USE_FIXED_POINT) complexi16_t *coeffs; - complexf_t constel_point; #else complexf_t *coeffs; #endif + complexf_t constel_point; + complexf_t target_point; float fpower; v29_rx_state_t *rx; static float smooth_power = 0.0f; @@ -191,22 +194,17 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex rx = (v29_rx_state_t *) user_data; if (constel) { - fpower = (constel->re - target->re)*(constel->re - target->re) - + (constel->im - target->im)*(constel->im - target->im); -#if defined(SPANDSP_USE_FIXED_POINT) - fpower /= 4096.0*4096.0; -#endif + constel_point.re = constel->re/V29_CONSTELLATION_SCALING_FACTOR; + constel_point.im = constel->im/V29_CONSTELLATION_SCALING_FACTOR; + target_point.re = target->re/V29_CONSTELLATION_SCALING_FACTOR, + target_point.im = target->im/V29_CONSTELLATION_SCALING_FACTOR, + fpower = (constel_point.re - target_point.re)*(constel_point.re - target_point.re) + + (constel_point.im - target_point.im)*(constel_point.im - target_point.im); smooth_power = 0.95f*smooth_power + 0.05f*fpower; #if defined(ENABLE_GUI) if (use_gui) { -#if defined(SPANDSP_USE_FIXED_POINT) - constel_point.re = constel->re/4096.0; - constel_point.im = constel->im/4096.0; qam_monitor_update_constel(qam_monitor, &constel_point); -#else - qam_monitor_update_constel(qam_monitor, constel); -#endif qam_monitor_update_carrier_tracking(qam_monitor, v29_rx_carrier_frequency(rx)); //qam_monitor_update_carrier_tracking(qam_monitor, (fpower) ? fpower : 0.001f); qam_monitor_update_symbol_tracking(qam_monitor, v29_rx_symbol_timing_correction(rx)); @@ -214,17 +212,10 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex #endif printf("%8d [%8.4f, %8.4f] [%8.4f, %8.4f] %2x %8.4f %8.4f %9.4f %7.3f %7.4f\n", symbol_no, -#if defined(SPANDSP_USE_FIXED_POINT) - constel->re/4096.0, - constel->im/4096.0, - target->re/4096.0, - target->im/4096.0, -#else - constel->re, - constel->im, - target->re, - target->im, -#endif + constel_point.re, + constel_point.im, + target_point.re, + target_point.im, symbol, fpower, smooth_power, @@ -234,24 +225,26 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex symbol_no++; if (--update_interval <= 0) { - len = v29_rx_equalizer_state(rx, &coeffs); - printf("Equalizer A:\n"); - for (i = 0; i < len; i++) + if ((len = v29_rx_equalizer_state(rx, &coeffs))) + { + printf("Equalizer A:\n"); + for (i = 0; i < len; i++) #if defined(SPANDSP_USE_FIXED_POINT) - printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/4096.0f, coeffs[i].im/4096.0f); + printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V29_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V29_CONSTELLATION_SCALING_FACTOR); #else - printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); + printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif #if defined(ENABLE_GUI) - if (use_gui) - { + if (use_gui) + { #if defined(SPANDSP_USE_FIXED_POINT) - qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); + qam_monitor_update_int_equalizer(qam_monitor, coeffs, len); #else - qam_monitor_update_equalizer(qam_monitor, coeffs, len); + qam_monitor_update_equalizer(qam_monitor, coeffs, len); +#endif + } #endif } -#endif update_interval = 100; } } @@ -470,7 +463,7 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) { - qam_monitor = qam_monitor_init(6.0f, NULL); + qam_monitor = qam_monitor_init(6.0f, V29_CONSTELLATION_SCALING_FACTOR, NULL); if (!decode_test_file) { start_line_model_monitor(129);