Hi I am trying to write some code in CRbasic that will allow me to manually calculate the running average of a variable sampled every 5 seconds, over a 5 minute period (so every 60 samples). I don't want to use AvgRun as my program does not continuously scan. Can anyone help? Thanks.
Aiden
AvgRun is fine to use at a five second (or greater) scan interval
Aiden
AvgRun is fine to use at a five second (or greater) scan interval.
Agreed, AvgRun should do the trick.
But if you don't share the sentiment, there should be a variety of ways to skin that cat.
Following is one
Public Meas, MeasRunAvg
Dim Array(60), I, J
BeginProg
Scan (1,Sec,0,0)
If IfTime (0,5,Sec) Then
I += 1 'advance pointer every 5 seconds
If IfTime (0,5,Min) Then I = 1 'reset pointer every 5 minutes
Array(I) = Meas 'put measurement into array
J = IIF (J<60,J+1,60) 'number of samples to avearge, maximum of 60
AvgSpa (MeasRunAvg,J,Array()) '5 min running Aaverage of speed, updated every 5s
EndIf
NextScan
EndProg