title: Implementing exponential moving average in Java
body: <p>I essentially have an array of values like this:</p>
  
  <pre><code>0.25, 0.24, 0.27, 0.26, 0.29, 0.34, 0.32, 0.36, 0.32, 0.28, 0.25, 0.24, 0.25
  </code></pre>
  
  <p>The above array is oversimplified, I'm collecting 1 value per millisecond in my real code and I need to process the output on an algorithm I wrote to find the closest peak before a point in time. My logic fails because in my example above, <code>0.36</code> is the real peak, but my algorithm would look backwards and see the very last number <code>0.25</code> as the peak, as there's a decrease to <code>0.24</code> before it.</p>
  
  <p>The goal is to take these values and apply an algorithm to them which will "smooth" them out a bit so that I have more linear values. (ie: I'd like my results to be curvy, not jaggedy)</p>
  
  <p>I've been told to apply an exponential moving average filter to my values. How can I do this? It's really hard for me to read mathematical equations, I deal much better with code. </p>
  
  <p>How do I process values in my array, applying an exponential moving average calculation to even them out? </p>
  
  <pre><code>float[] mydata = ...
  mySmoothedData = exponentialMovingAverage(mydata, 0.5);
  
  float[] exponentialMovingAverage(float[] input, float alpha) {
      // what do I do here?
      return result;
  }
  </code></pre>