The scenario is like this. I need to generate 90,100 random numbers and on that number I need to compute the simple moving average?
What method is the best to compute the moving average?
The scenario is like this. I need to generate 90,100 random numbers and on that number I need to compute the simple moving average?
What method is the best to compute the moving average?
Probably the fastest is as follows in pseudo-code:
# P: input signal array
# S: sum accumulator
# I: counter
# N: number of samples in your sliding average
S <- P[0] + P[1] + ... + P[N-1]
I <- N
forever:
save_new_result(S / N)
S <- S - P[I-N] + P[I]
I <- I + 1
So, you actually have one subtract, one divide-by-constant, and one add operation per sample.