Trying to take a 100 sample average

I am trying to collect data from a pressure transducer. I need a continuous average of the last 100 data points. New data comes in and old data comes out. And every loop I need to take an average. I need this to happen in real time. I have tried this in a user program and RMCTools says the program takes too long. I am sure I’m missing something simple but I have tried everything I can think of.

I have tried to use something like this “numR := ( num[0] + num[1] + num[2] + num[3] ) / 4”  and it doesn’t work with 100 samples and kind of unreasonable.

I am using RMC 75E
Any help is much appreciated. Thanks in advance.

Computing a moving average by summing all the data points every time is not very efficient because most of the computation is the same every time.
Implementing a simple moving average will greatly reduce the computation overhead of the calculation. A simple moving average works by keeping track of the current sum of all data points. When a new sample is collected, the oldest sample is removed from the sum and the new sample is added. This method is scalable for large data sets.

Attached is a user program for computing a moving average. To import this program into your project, right click on User Programs and click Import User Program.
MovingAverage.rmcprog (2.92 KB)

My favorite moving average, which is easy to implement and has a very low memory requirement is the exponential moving average. This average assigns exponentially lower weight to samples collected farther in the past, and can be written as one line.

 average := average + 2 / (n + 1) * (sample - average)