Skip to content

Instantly share code, notes, and snippets.

@berikv
Last active December 15, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berikv/5186106 to your computer and use it in GitHub Desktop.
Save berikv/5186106 to your computer and use it in GitHub Desktop.
Running average as implemented in the Linux/Unix kernels (shown with the `w` command). Usages can be frame rate, accelerometer, etc.
// A factor of 0.5 means that every newValue will have a 50% impact on the average
// Usage: self.average = updateRunningAverage(self.average, newValue, 0.3);
#define updateRunningAverage(average, newValue, factor) (((newValue) * (factor)) + ((average) * (1.0 - (factor))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment