added math functions for non-linear IIR filtering and hysteresis

This commit is contained in:
Volker Fischer 2011-06-16 11:25:38 +00:00
parent 07034ba8bc
commit e58f2d37a2

View file

@ -691,6 +691,39 @@ public:
{
return (int) ( ( x - floor ( x ) ) >= 0.5 ) ? ceil(x) : floor(x);
}
static void UpDownIIR1 ( double& dOldValue,
const double& dNewValue,
const double& dWeightUp,
const double& dWeightDown )
{
// different IIR weights for up and down direction
if ( dNewValue < dOldValue )
{
dOldValue =
dOldValue * dWeightDown + (1.0 - dWeightDown) * dNewValue;
}
else
{
dOldValue =
dOldValue * dWeightUp + (1.0 - dWeightUp) * dNewValue;
}
}
static int DecideWithHysteresis ( const double dValue,
const int iOldValue,
const double dHysteresis )
{
// apply hysteresis
if ( dValue > static_cast<double> ( iOldValue ) )
{
return round ( dValue - dHysteresis );
}
else
{
return round ( dValue + dHysteresis );
}
}
};