1
0
Fork 0

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.
This commit is contained in:
curt 2005-09-16 20:21:15 +00:00
parent e17bc29986
commit e60223a952

View file

@ -651,14 +651,14 @@ FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node)
} }
output.resize(2, 0.0); output.resize(2, 0.0);
input.resize(samples, 0.0); input.resize(samples + 1, 0.0);
} }
void FGDigitalFilter::update(double dt) void FGDigitalFilter::update(double dt)
{ {
if ( input_prop != NULL ) { if ( input_prop != NULL ) {
input.push_front(input_prop->getDoubleValue()); 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 :-) // no sense if there isn't an input :-)
enabled = true; enabled = true;
} else { } else {