From e9263c9c9d84b26c738b3ca2d505f3732e5f81ff Mon Sep 17 00:00:00 2001 From: Kamal Mostafa Date: Sun, 19 Aug 2012 15:58:08 -0700 Subject: [PATCH] fsk: fix noise <= EPSILON handling Handle noise <= EPSILON better; fixes (im)perfect test cases on i386. --- src/fsk.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fsk.c b/src/fsk.c index 0967b41..52f670e 100644 --- a/src/fsk.c +++ b/src/fsk.c @@ -21,6 +21,7 @@ #include #include #include // fabs, hypotf +#include // FLT_EPSILON #include #include #include @@ -274,25 +275,24 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, float total_bit_sig = 0.0, total_bit_noise = 0.0; for ( bitnum=0; bitnum<(n_bits-1); bitnum++ ) { + // Deal with floating point data type quantization noise... + // If total_bit_noise <= FLT_EPSILON, then assume it to be 0.0, + // so that we end up with snr==inf. total_bit_sig += bit_sig_mags[bitnum]; - total_bit_noise += bit_noise_mags[bitnum]; + if ( bit_noise_mags[bitnum] > FLT_EPSILON ) + total_bit_noise += bit_noise_mags[bitnum]; } - // Deal with floating point data type quantization noise... - // If total_bit_noise is so small that (sig-noise) appears to == sig, - // then force noise=0.0, so that we end up with snr==inf. - float d = total_bit_sig - total_bit_noise; - if ( d == total_bit_sig) - total_bit_noise = 0.0f; - // Compute the "frame SNR" float snr = total_bit_sig / total_bit_noise; float avg_bit_sig = total_bit_sig / (n_bits-1); #ifdef FSK_DEBUG float avg_bit_noise = total_bit_noise / (n_bits-1); - debug_log(" snr=%.6f avg{ bit_sig=%.6f bit_noise=%.6f }\n", - snr, avg_bit_sig, avg_bit_noise); + debug_log(" snr=%.6f avg{ bit_sig=%.6f bit_noise=%.6f (%s) }\n", + snr, avg_bit_sig, avg_bit_noise, + avg_bit_noise == 0.0 ? "zero" : "non-zero" + ); #endif # ifdef FSK_MIN_MAGNITUDE