title: Computing standard deviation over a circular buffer
body: <p>I need to calculate the standard deviation of values are stored in a circular buffer. The final algorithm will run on a resource-constrained device, thus I want it to be as lightweight as possible. The naive approach would be to re-evaluate the standard deviation over the whole buffer each time that a new value is pushed in, but it would be really slow. Ideally, I'd like an algorithm that dynamically updates the current value of standard deviation as new values are pushed in.</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods" rel="nofollow">Wikipedia reports some techniques for rapid calculation</a>, but they can be used on streams: in my case when a new value is pushed in, the standard deviation should be calculated as if the last value that has been popped never existed.</p>
  
  <p>tl;dr: how can I calculate standard deviation over a circular buffer with minimal computational effort?</p>