From 793183469d2c02e59ee91a072b8f59153870415c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 6 Jun 2015 13:38:55 +0200 Subject: ewma: prevent NaN after division by zero Issue: #169 --- ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp index cdf18263..86cc2a96 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp @@ -63,6 +63,8 @@ void FTNoIR_Filter::filter(const double *input, double *output) last_noise[i] = noise_alpha*noise + (1.0-noise_alpha)*last_noise[i]; // Normalise the noise between 0->1 for 0->9 variances (0->3 stddevs). double norm_noise = std::min(noise/(9.0*last_noise[i]), 1.0); + if (std::isnan(norm_noise)) + norm_noise = 0; // Calculate the smoothing 0.0->1.0 from the normalized noise. // TODO(abo): change kSmoothingScaleCurve to a float where 1.0 is sqrt(norm_noise). double smoothing = 1.0 - pow(norm_noise, s.kSmoothingScaleCurve/20.0); -- cgit v1.2.3