Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Alternative to AvgRun


AidanT Oct 5, 2012 03:06 PM

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.


Grant Oct 8, 2012 10:25 PM

Aiden

AvgRun is fine to use at a five second (or greater) scan interval


Grant Oct 8, 2012 10:26 PM

Aiden

AvgRun is fine to use at a five second (or greater) scan interval.


Sam Oct 9, 2012 02:14 AM

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

Log in or register to post/reply in the forum.