Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Moving average filter

2009-07-18 by Roy E. Burrage

How about just modifying an Atmel application note?

       http://www.atmel.com/dyn/products/app_notes.asp?family_id=607

Look at AVR222 and 223.  Both address digital filters.




dpharris@telus.net wrote:
> Use a revolving buffer to store your last 16 values.  
>
> Do an initial sum from the first 16 values.  
>
> Then at each step: 
>
>   if(++i>15) i=0;   // get the next mafdata slot
>   mafsum = mafsum + data - mafdata[i];  // update running sum
>   mafdata[i] = data;   // remember latest value in slot
>
>   data = mafsum / 16;  // calculate running average
>   
>   Quoting Adeilton Oliveira <adeiltonjunior@terra.com.br>:
>
> David
>
>   
>> Hello.
>>
>> I don't know how the division operation is internally implemented, but I 
>> think in your case you can use >>4 instead of /16.
>>
>>
>>
>> ?????????? ????? ?????????? wrote:
>>     
>>> Hello!
>>>
>>> I using WinAVR 20090313 and ATMega32.
>>> I write code for time critical application.
>>> There is a moving average filter algorithm.
>>>
>>> unsigned char data = 0;
>>> unsigned char i = 0;
>>> unsigned char mafinit = 0;
>>> unsigned int mafsum = 0;
>>> unsigned char mafdata[16];
>>>
>>> if (!mafinit)
>>> {
>>> for (i = 0; i < 16; i++)
>>> mafdata[i] = data;
>>> mafinit = 1;
>>> }
>>>
>>> for (i = 0; i < 15; i++)
>>> {
>>> mafdata[i] = mafdata[i+1];
>>> mafsum += mafdata[i];
>>> }
>>> mafdata[15] = data;
>>> mafsum += data;
>>> data = mafsum / 16;
>>>
>>> Are there any ways to speedup algorithm?
>>>
>>> -- 
>>> Best regards,
>>> Roman Antoshchenkov
>>> mailto:djantoxa@rambler.ru <mailto:djantoxa%40rambler.ru>
>>>
>>>
>>>       
>>
>> ------------------------------------
>>
>> Yahoo! Groups Links
>>
>>
>>
>>
>>     
>
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.392 / Virus Database: 270.13.19/2245 - Release Date: 07/18/09 05:57:00
>
>   


[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.