Forum Discussion
Altera_Forum
Honored Contributor
12 years ago --- Quote Start --- For averaging 2^n samples all you need is discard n LSBs from result of accumulator (as explained in some of above posts). for non power of 2 samples there are some tricks to avoid division e.g. if number of samples is 1000 then average = sum/1000 = sum/1024 * 1.024 ~= sum/1024 *(1+1/64+1/128) hence average = sum(discard 10 LSBs) + sum(discard 16 LSBs) + sum(discard 17 LSBs) --- Quote End --- Ok Kaz, but this way you need more system resources, I mean logic gates in fpga or computation time in a programming language. In other words you are still implementing some sort of division algorithm. I would keep on my idea, which is also the one exploited by the sample code at start of this thread: if you don't mind the x1000 (or whatever) factor you can quietly avoid the division. If you later need to compare this 'average x 1000' with something else, it will be easier to multiply this one x1000 than dividing the average result.