// One-time calculations (can be pre-calculated at compile-time and loaded with constants)
DecayFactor = exp(-2.0 * PI * CutoffFrequency / SampleRate);
AmplitudeFactor = (1.0 - DecayFactor);
// Filter Loop Function ----- THIS IS IT -----
double Filter(double newInput)
{
MovingAverage *= DecayFactor;
MovingAverage += AmplitudeFactor * newInput;
return (MovingAverage);
}
(credits to: http://electronics.stackexchange.com/a/31907)
Nincsenek megjegyzések:
Megjegyzés küldése