Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Moving average filter

2009-07-17 by Adeilton Oliveira

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>
>
>

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.