Average of reading on IR sensor

@chagrin

I think your filter handles large changes and small noise the same way. I expect most people want the fine noise (last bit) to be suppressed.

I mostly use something like this

void loop() 
{
  x = x - 0.15 * (x - analogRead(PIN) );  // 0.15 can be any value between 0.001 and 1.0
}

(it is a cleaner variation of x = 0.85x + 0.15analogRead(PIN); as it only has one tuneable param in the formula.