Yn=Yn-1+(1/kana*(Xn-Yn-1)) // Averaging formula

Hi all,

Been meaning to re-use this little averaging formula for years.....now that I've gotten into Arduino I have it working for me again.

The neat thing is that it's an integrating averaging formula, so it's average is not affected by spurious large spikes.

I currently use it to drive an RC type servo drive.......thus rather than have the servo jump fast from one position to another if the input changes, the servo will smoothly transition from one position to another.

The other neat thing is that apart from setup it's one line of Arduino code to implement.

Yn=Yn-1+(1/kana*(Xn-Yn-1)) // Averaging formula

Xn = AI_Raw0
Yn = AnaIY0
kana = constant (suggest vary this anywhere from 0.1 to 10)

Note:- Make sure you pre-load AnaIY0 with a one-off copy of AI_Raw0 at startup. It will help have the formula settle quickly on startup.

AnaIY0 = AnaIY0 - 1 + (1 / kana * ((float)AI_Raw0 - AnaIY0 - 1));

Well, I hope it's useful to someone!

Ian.

That is very useful, thank you.