From 1ed3b8465ae197f041e97f2cfe4840158c0d847e Mon Sep 17 00:00:00 2001 From: Kamal Mostafa Date: Fri, 24 Aug 2012 22:38:41 -0700 Subject: [PATCH] fsk: confidence algo #6: "SNR * (1-divergence)" Disabled all the hardcoded noise limiters. --- src/fsk.c | 67 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/fsk.c b/src/fsk.c index 96288b4..28b9c1d 100644 --- a/src/fsk.c +++ b/src/fsk.c @@ -174,7 +174,7 @@ fsk_bit_analyze( fsk_plan *fskp, float *samples, unsigned int bit_nsamples, } -/* returns confidence value [0.0 to 1.0] */ +/* returns confidence value [0.0 to INFINITY] */ static float fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, int n_bits, const char *expect_bits_string, @@ -188,6 +188,11 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, unsigned int bit_begin_sample; int bitnum; +// various deprecated noise limiter schemes: +//#define FSK_MIN_BIT_SNR 1.4 +//#define FSK_MIN_MAGNITUDE 0.10 +//#define FSK_AVOID_TRANSIENTS 0.7 + const char *expect_bits = expect_bits_string; /* pass #1 - process and check only the "required" (1/0) expect_bits */ @@ -206,8 +211,11 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, if ( (expect_bits[bitnum] - '0') != bit_values[bitnum] ) return 0.0; /* does not match expected; abort frame analysis. */ - // FSK_MIN_MAGNITUDE serves as a noise limiter -# define FSK_MIN_MAGNITUDE 0.10 +#ifdef FSK_MIN_BIT_SNR + float bit_snr = bit_sig_mags[bitnum] / bit_noise_mags[bitnum]; + if ( bit_snr < FSK_MIN_BIT_SNR ) + return 0.0; +#endif # ifdef FSK_MIN_MAGNITUDE // Performance hack: reject frame early if sig mag isn't even half @@ -215,13 +223,9 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, if ( bit_sig_mags[bitnum] < FSK_MIN_MAGNITUDE/2.0 ) return 0.0; // too weak; abort frame analysis # endif - } -// Note: CONFIDENCE_ALGO 3 does not need AVOID_TRANSIENTS -#define AVOID_TRANSIENTS 0.7 -// -#ifdef AVOID_TRANSIENTS +#ifdef FSK_AVOID_TRANSIENTS // FIXME: fsk_frame_analyze shouldn't care about start/stop bits, // and this really is only correct for "10dd..dd1" format frames anyway: // FIXME: this is totally defective, if the checked bits weren't @@ -232,7 +236,7 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, * diff between start bit and stop bit strength not be "large". */ float s_mag = bit_sig_mags[1]; // start bit float p_mag = bit_sig_mags[n_bits-1]; // stop bit - if ( fabs(s_mag-p_mag) > (s_mag * AVOID_TRANSIENTS) ) { + if ( fabs(s_mag-p_mag) > (s_mag * FSK_AVOID_TRANSIENTS) ) { debug_log(" avoid transient\n"); return 0.0; } @@ -248,17 +252,24 @@ fsk_frame_analyze( fsk_plan *fskp, float *samples, float samples_per_bit, &bit_values[bitnum], &bit_sig_mags[bitnum], &bit_noise_mags[bitnum]); + +#ifdef FSK_MIN_BIT_SNR + float bit_snr = bit_sig_mags[bitnum] / bit_noise_mags[bitnum]; + if ( bit_snr < FSK_MIN_BIT_SNR ) + return 0.0; +#endif } -#define CONFIDENCE_ALGO 5 +//#define CONFIDENCE_ALGO 5 +#define CONFIDENCE_ALGO 6 float confidence; -#if CONFIDENCE_ALGO == 5 +#if CONFIDENCE_ALGO == 5 || CONFIDENCE_ALGO == 6 float total_bit_sig = 0.0, total_bit_noise = 0.0; - for ( bitnum=0; bitnum<(n_bits-1); bitnum++ ) { + for ( bitnum=0; bitnum