On 11.04.16 14:05, Nicklas Karlsson wrote: > > Is is rather straightforward to calculate from for example the last > 100 arrival times but a moving average algorithm would be preferred to > reduce CPU load. Do anybody have any ideas?
If the average is over 64 or 128 samples, then the divide is reduced to a 6 or 7 bit rightshift. Or does your chosen micro have hardware divide of sufficient length? To average the samples, they need to be stored, I figure, but the long summation need not be performed each time. I'd be tempted to store them in a circular buffer, then subtract the oldest from the running sum, add the new sample, save the result as the new running sum, then divide by 64 or 128, using what's fastest to provide the moving average. Writing the new sample to the circular buffer overwrites the oldest. The running sum will be a longer integer by 6 or 7 bits, naturally, so might necesstitate a double precision divide, making the right shift more competitive, perhaps. Erik ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/ gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532 _______________________________________________ Emc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-users
