fsk: fix noise <= EPSILON handling
Handle noise <= EPSILON better; fixes (im)perfect test cases on i386.
This commit is contained in:
parent
96ec6450bb
commit
e9263c9c9d
20
src/fsk.c
20
src/fsk.c
|
@ -21,6 +21,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h> // fabs, hypotf
|
#include <math.h> // fabs, hypotf
|
||||||
|
#include <float.h> // FLT_EPSILON
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -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;
|
float total_bit_sig = 0.0, total_bit_noise = 0.0;
|
||||||
for ( bitnum=0; bitnum<(n_bits-1); bitnum++ ) {
|
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_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"
|
// Compute the "frame SNR"
|
||||||
float snr = total_bit_sig / total_bit_noise;
|
float snr = total_bit_sig / total_bit_noise;
|
||||||
|
|
||||||
float avg_bit_sig = total_bit_sig / (n_bits-1);
|
float avg_bit_sig = total_bit_sig / (n_bits-1);
|
||||||
#ifdef FSK_DEBUG
|
#ifdef FSK_DEBUG
|
||||||
float avg_bit_noise = total_bit_noise / (n_bits-1);
|
float avg_bit_noise = total_bit_noise / (n_bits-1);
|
||||||
debug_log(" snr=%.6f avg{ bit_sig=%.6f bit_noise=%.6f }\n",
|
debug_log(" snr=%.6f avg{ bit_sig=%.6f bit_noise=%.6f (%s) }\n",
|
||||||
snr, avg_bit_sig, avg_bit_noise);
|
snr, avg_bit_sig, avg_bit_noise,
|
||||||
|
avg_bit_noise == 0.0 ? "zero" : "non-zero"
|
||||||
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# ifdef FSK_MIN_MAGNITUDE
|
# ifdef FSK_MIN_MAGNITUDE
|
||||||
|
|
Loading…
Reference in New Issue