summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-06-06 13:38:55 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-06-06 13:38:55 +0200
commit793183469d2c02e59ee91a072b8f59153870415c (patch)
treecf3e35a88e4f9c687269d7e40e77d188bb577859
parent8fff801752845c052dd7e5f8be70a444fa1455ef (diff)
ewma: prevent NaN after division by zero
Issue: #169
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp2
1 files changed, 2 insertions, 0 deletions
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<double>(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);