From e60223a9529849183623a09a6ce76ffb346b4e8a Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 16 Sep 2005 20:21:15 +0000 Subject: [PATCH] Lee Elliot: >> Hello List, >> >> I think there's a small bug in the moving-average filter in >> xmlauto.cxx >> >> I noticed that the output from it was always out a bit and >> checking with a calculator showed that it seemed to be dividing >> by the number of samples + 1 instead of just the number of >> samples. >> >> subtracting 1 from 'samples' in line 702 seems to fix the problem >> and as 'samples' doesn't seem to be used elsewhere I think it's >> safe. Possibly implies that the number of samples may be one >> less than specified but I'm not familiar enough with c++ to spot >> it. Roy Ovesen: You are right. I would suggest resizing input[] to (samples + 1) instead. Change lines 654 and 661 to: input.resize(samples + 1, 0.0); That way we average over the number of samples as configured. --- src/Autopilot/xmlauto.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx index ac0953b6d..bee93b588 100644 --- a/src/Autopilot/xmlauto.cxx +++ b/src/Autopilot/xmlauto.cxx @@ -651,14 +651,14 @@ FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node) } output.resize(2, 0.0); - input.resize(samples, 0.0); + input.resize(samples + 1, 0.0); } void FGDigitalFilter::update(double dt) { if ( input_prop != NULL ) { input.push_front(input_prop->getDoubleValue()); - input.resize(samples, 0.0); + input.resize(samples + 1, 0.0); // no sense if there isn't an input :-) enabled = true; } else {