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.

Average of a value in an variable interval


simon Dec 7, 2015 06:51 AM

I have an application where I want to store the average of a value over a period of time. The logger is a CR1000.

I can use the DataInterval instruction in my DataTable to achieve that, if the interval of interest always occurs at the same time, with respect to the real time clock.

In this case, that can not be guaranteed.

Let's say I want to collect readings that will be used to compute an average over a 3 minute period and I want to do this process every 15 minutes. The other 12 minutes of the interval, the data is superfluous and the sensor won't be active.

I could do that with DataInterval (0,15,min,1) and put a flag around CallTable, whose state was driven by a TimeintoInterval(12,15,min) condition . That would get me the last 3 minutes of the interval each time.

Or I could use DataInterval (3,15,min,1) and have the flag driven by TimeintoInterval(0,15,min) to get the first 3 minutes of the interval each time.

The issue is that it won't always be the first 3 minutes of the 15 minute interval that I'm interested in. The sensor has to be positioned a particular distance below the surface of the water and the water is tidal, so the time it takes to get the sensor in the correct position is variable. Only when the sensor is in the correct location, do the three minutes begin and the average needs to be stored at the end of this 3 minute period.

I've tried playing with the DataEvent instruction, but the best I can get is for it to log a record every scan (the average of one value) in that 3 minute period.

My test code to simulate this (below) is based on a counter incrementing every scan (1 second) and the logging period being for 20 seconds: from Counter = 6 through to Counter = 26. I hope to log an average of the Counter, which would give me a single record at the end of the 20 second period, with a value of 16.

I get this same result in both of the following examples.
The table is called every scan (unconditionally).

In the real application, the start and stop conditions can be defined as can the number of records required for the event.

DataTables used in the tests

DataTable (WQ_Data_Avg,True,1000)
DataEvent (20,Counter=26,Counter>=26,0)
Average (1,Counter,IEEE4,False)
EndTable


DataTable (WQ_Data_Avg,True,1000)
DataEvent (20,Counter=6,Counter>=26,0)
Average (1,Counter,IEEE4,False)
EndTable


I am at the point where I am thinking that I will have to compute the average myself by reading all the individual samples out of the table or by performing the intermediate processing in public (or Dim'ed) variables as the readings come in. This is OK as I've done this before, but I was hoping that there was another way to do it.

Can DataEvent be used to compute statistical values like Average?

Is coding the average manually, the only way to achieve this?

Thanks

Simon


JDavis Dec 7, 2015 04:24 PM

If the average would always be over a 3 minute period, you could use the AvgRun instruction. Just always calculate the running average, and only save it when you need it.

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