Hackers in Residence - Sound and Motion Reactivity for Wearables
Software, Integration, and Smoothing
After selecting these components it comes time for some serious code, integration, and smoothing.
EWMA: Exponentially Weighted Moving Average
I hope we've all learned what it means to take the average of a given dataset. The average volume wouldn't be very interesting and certainly not very reactive. By calculating simple average over time of results will converge on a single value. This doesn't work because even large changes in sound or motion would not even be detected. It can also be a somewhat expensive operation to always be adding to bigger numbers and dividing.
A moving average is a great optimization and it allows you to recalculate each time a new datapoint arrives. This is a great optimization but continues to lack reactivity. I want instant feedback when loud sounds occur.
Exponential weighting really helps maintain this reactivity by weighting new data much more than the past values. This allows for instant feedback upon drastic changes while still avoiding the flicking and flashing experienced from noisy data.
In doing my research I found an EWMA is very often used to analyze financial markets as they need to quickly detect sudden rises and falls without paying too much mind to the minimal changes. This blog post does an excellent job of describing EWMA in detail for our purposes of smoothing.
I found a great Arduino library for EWMA and was quickly able to apply this smoothing with different coefficients to my motion axes and sound frequency ranges.