It'd be nice to be able to seed the filter with some sort of sane value (as an optional parameter) so that the initial returns of .Compute() aren't skewed down while the window fills.
Perhaps something like:
#include <SavLayFilter.h>
const double seedValue = 123.45;
double outputValue;
SavLayFilter testFilter( &outputValue, 0, 5, seedValue );
Without this feature, here's a workaround:
#include <SavLayFilter.h>
double outputValue;
SavLayFilter testFilter( &outputValue, 0, 5 );
void setup()
{
// Seed a sane value
outputValue = 123.45;
// Execute the filter until its output reaches at least 90% of the seed
while( true )
{
if( testFilter.Compute() > outputValue * 0.9 )
break;
}
}
void loop()
{
// The filter is primed, so now the first calls to testFilter.Compute()
// will output something more sane instead of 0
}
...or, instead of a seed, one could prime the filter with the first value (would be even better if the very first call to .Compute() handled this internally):
#include <SavLayFilter.h>
double outputValue;
SavLayFilter testFilter( &outputValue, 0, 5 );
bool filterPrimed;
void setup()
{
filterPrimed = false;
}
void loop()
{
// Read a value from a sensor (fake function used for this example)
outputValue = readSensor();
// This will initially be false, so we'll continue to call .Compute() until the returned
// value is within 90% of the original value. This routine will only occur once.
while( !filterPrimed )
{
if( testFilter.Compute() > ( outputValue * 0.9 ) )
filterPrimed = true;
}
// At this point, the filter is primed, and the first several calls to .Compute() will return sane-ish values
//// If you reset the filter, you must also re-trigger the primer
// testFilter.resetValues();
// filterPrimed = false;
}
It'd be nice to be able to seed the filter with some sort of sane value (as an optional parameter) so that the initial returns of
.Compute()aren't skewed down while the window fills.Perhaps something like:
Without this feature, here's a workaround:
...or, instead of a seed, one could prime the filter with the first value (would be even better if the very first call to
.Compute()handled this internally):