Last active
October 5, 2023 22:58
-
-
Save trevnorris/b580efd8769a89a78321329d9f6ba10e to your computer and use it in GitHub Desktop.
Convert discrete data from irregular duration event loop iterations to time series data using a Poisson window function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Calculate the exponential moving average using the Poisson window function | |
* combined with a time constant adjustment so even though the calculation is | |
* only done once every loop, the smoothing curve acts as if it was time-series | |
* data. | |
* | |
* The expanded equation for this is: | |
* | |
* /-ΔT \ | |
* |----| | |
* \ τ / | |
* s = s + (1 - e ) * (x - s ) | |
* t (t-1) t (t-1) | |
* | |
* Where: | |
* ΔT - the difference in time since the last calculation in seconds | |
* τ - the time constant for the calculation in seconds | |
* x - new value to add to the exponential rolling avg | |
*/ | |
static double inc_rolling_avg(double avg, double val, double diff, double con) { | |
return avg + (1 - exp(-diff / con)) * (val - avg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment