A 10-Point moving average filter that returns a float each time a new value is added to the moving average array.

Fork of MovingAverageFilter by Karim Azzouz

Committer:
joe4465
Date:
Fri May 16 14:17:38 2014 +0000
Revision:
2:21b70641f866
Parent:
1:fbc57eb4e61d
Added RC control - still not holding attitude correctly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KarimAzzouz 1:fbc57eb4e61d 1 #include "MAF.h"
KarimAzzouz 1:fbc57eb4e61d 2
joe4465 2:21b70641f866 3 MAF::MAF()
joe4465 2:21b70641f866 4 {}
KarimAzzouz 1:fbc57eb4e61d 5
joe4465 2:21b70641f866 6 float MAF::update(float data)
joe4465 2:21b70641f866 7 {
KarimAzzouz 1:fbc57eb4e61d 8 _k[0] = data;
KarimAzzouz 1:fbc57eb4e61d 9 _result = _k[0]*0.1 + _k[1]*0.1 + _k[2]*0.1 + _k[3]*0.1 + _k[4]*0.1 + _k[5]*0.1 + _k[6]*0.1 + _k[7]*0.1 + _k[8]*0.1 + _k[9]*0.1 ;
KarimAzzouz 1:fbc57eb4e61d 10 _k[9] = _k[8];
KarimAzzouz 1:fbc57eb4e61d 11 _k[8] = _k[7];
KarimAzzouz 1:fbc57eb4e61d 12 _k[7] = _k[6];
KarimAzzouz 1:fbc57eb4e61d 13 _k[6] = _k[5];
KarimAzzouz 1:fbc57eb4e61d 14 _k[5] = _k[4];
KarimAzzouz 1:fbc57eb4e61d 15 _k[4] = _k[3];
KarimAzzouz 1:fbc57eb4e61d 16 _k[3] = _k[2];
KarimAzzouz 1:fbc57eb4e61d 17 _k[2] = _k[1];
KarimAzzouz 1:fbc57eb4e61d 18 _k[1] = _k[0];
KarimAzzouz 1:fbc57eb4e61d 19
KarimAzzouz 1:fbc57eb4e61d 20 return _result;
joe4465 2:21b70641f866 21 }