I'm fairly new to python but have a script that is calculating the number of pulses every second - anywhere between 0 and 150.
However, a snapshot of one of these counts would be too random and they need smoothing with an average.
With my limited knowledge, I could count second one, count second two, ...three... Store then in separate variables and then every 30 seconds average all thirty variables, reset and start again. Ultimately, my output would be every 30 seconds for the average.
I've been told that there is a way to calculate a running/moving average, i.e 30 values stored, average taken. New input comes in every second, oldest value gets kicked out, new average taken. Consequently it is a smoother running average of the last 30 inputs and if needed the output can be taken every second.
Has anyone got a similar code or example they could send me? Or better still adapt my code!
Code: Select all
while True: time.sleep(1) count = wind_tally() # brings through the new 1hz count print count - old-count # prints latest count or could be count1 if averaging old-count = count
Count1 = count-old. ..next into count2... etc
Any help appreciated.