I have tried few running averaging techs for smoothing the change in ADC data in AtMega48 for controlling lights(PWM) when rotating a pot(ADC).
The filters (pseudo codes):
Moving average:
adc_avg += new adc_raw;
adc_avg >>= 1;
8-point Moving Average Filter:
fill adc_raw_array[i] = adc_raw;
adc_raw_array[8] <-- delete left most, move left, push adc_raw.
adc_avg = sum(adc_raw_array);
adc_avg >>=3 ; // divide by 8
I observed that the filters are very nice. But slow in response which is expected.
I am looking for a techniques like Exponential moving average. Said to be more responsive. Is there another like this one? As it says:
adc_Eavg = α * adc_raw + ( 1 - α ) * adc_Eavg ;
where α is between 0 and 1.
How to code and optimize those; code wise (without using floats) ? Or How would I convert the floats to corresponding integers for making code small, fast and responsive one.
I tried as
adc_Eavg += α * ( adc_raw - adc_Eavg );
and I kept α = 1;
Other then that it wont work as expected. Because I'd've to change all the variables to float.
Please do not concentrate on following statement for the time being but note. Keeping floats in my code base is filling the program memory from 45% to 137%, in case of
adc_avg = adc_avg * 0.8f + adc_raw * 0.2f;