]> git.mxchange.org Git - flightgear.git/commitdiff
Lee Elliot:
authorcurt <curt>
Fri, 16 Sep 2005 20:21:15 +0000 (20:21 +0000)
committercurt <curt>
Fri, 16 Sep 2005 20:21:15 +0000 (20:21 +0000)
>> 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

index ac0953b6d4c9fc6e51ca379477f68df9a1874cfc..bee93b588f9d53c6655ca96f62fa7816d85ab7a2 100644 (file)
@@ -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 {