"Average" Function_Campbellsci论坛问答

When the program below executes the Average command, how many data points is it averaging. It seems like since the table is called after every scan, the Average would be
just the average of one value... How does this function work?

"Average" Function_Campbellsci论坛问答


'Declare Variables and Units
Public BattV
Units BattV=Volts

'Define Table
DataTable(BatteryAverageTable,True,-1)
DataInterval(0,1,Min,10)
Average(1,BattV,FP2,False)
EndTable

'Main Program
BeginProg
Scan(1,Sec,1,0)
Battery(BattV)
CallTable(BatteryAverageTable)
NextScan
EndProg

新对话如下:

Your

DataInterval(0,1,Min,10)

and

Scan(1,Sec,1,0)

together are driving how many samples are going into the average. For 59 out of 60 seconds the battery voltage measurement is simply added to an accumulator and a counter is incremented. At the top of the minute the last battery voltage is added to the accumulator and the counter is incremented one more time. The accumulator is then divided by the counter, which should be at 60 in this case, and the resulting average gets written to the table. The accumulator and counter are then cleared and it starts all over at one second after the top of the minute in this case.

新对话如下:

This reminds me of a mistake I have seen a few times, more with array based loggers but I think it applies to table based ones as well. The problem is when the call to the table or final storage instructions are put within an if statement or not executed every pass through the program. When you do this the average instruction only accumulates and counts when the program enters into the if statement. For example:

1: Batt Voltage (P10)
1: 1 Loc [ BattV ]

2: If time is (P92)
1: 0 Minutes (Seconds --) into a
2: 1 Interval (same units as above)
3: 30 Then Do

3: Do (P86)
1: 10 Set Output Flag High (Flag 0)

4: Real Time (P77)
1: 1220 Year,Day,Hour/Minute (midnight = 2400)

5: Average (P71)
1: 1 Reps
2: 1 Loc [ BattV ]

6: End (P95)

In this case your average is only going to be of 1 value. It would be better to just set the output flag with P92 and have the final storage instructions just below that instruction.

新对话如下:

I have a similar question. This is how my CR1000 program works (simplified):

'Program start/////////////////////
Public MyVar

DataTable(MyTable,1,-1)
DataInterval(0,30,Min,10)
Average(1,MyVar,IEEE4,False)
Maximum(1,MyVar,IEEE4,False,False)
EndTable

BeginProg
Scan(30,Sec,0,0)
[measure something and put it in MyVar]
If TimeIntoInterval(0,30,min) Then CallTable MyTable
NextScan
EndProg
'Program end/////////////////////

The IF statement should have been left out. I have corrected the code now but I have valuable data from earlier on from this station that I hope to recover. Please tell me in more detail how Average and Maximum works.

The data before I erased the IF statement is corrupted I can tell but now it looks fine. What are the difference between before and now?

When does Average and Maximum get cleared and ready for a new run?


I hope someone can help me with this. If so I might be able to make an inverse filter to get the original data.

Thank you.

* Last updated by: Bo on 2/22/2010 @ 7:11 AM *

新对话如下:

"Your

DataInterval(0,1,Min,10)

and

Scan(1,Sec,1,0)

together are driving how many samples are going into the average. For 59 out of 60 seconds the battery voltage measurement is simply added to an accumulator and a counter is incremented. At the top of the minute the last battery voltage is added to the accumulator and the counter is incremented one more time. The accumulator is then divided by the counter, which should be at 60 in this case, and the resulting average gets written to the table. The accumulator and counter are then cleared and it starts all over at one second after the top of the minute in this case."

Thanks for clarifying this. I read the help file for the average function but it didn't mention the accumulator and counter. Is there a document where functions like this, that work with the DataTable and Scan instructions, are documented in this level of detail?

新对话如下:

Bo - Before you removed the If TimeIntoInterval(0,30,min)... statement from your program you were getting the instantaneous value (same as Sample instruction) rather than an average. There isn't anyway to figure out what the average would be when you only have an instantaneous value from the same time interval.

新对话如下:

VAtachnologies14

The following is in the CR9000X manual. Would this info be informative enough if it was in the other manuals?

4.2.8.4 Data Output Processing Instructions

The output processing instructions included in a data table declaration determine the values that are stored to the data table. The most commonly used output processing instructions are Average, Maximum, Minimum, and Sample.
The table must be called by the program, using the allTable instruction,in order for the output processing to take place. When the Data Table is called via the CallTable instruction, the data storage processing instructions
process the variables' current values. If the trigger conditions for the Table are true, the processed values are stored to the data table and the output processing is reset.

See Section 6.4 Output Processing for information on Data Processing instructions.

Average is an output processing instruction that will output the average of a variable over the output interval. The parameters are repetitions - the number of elements in an array for which to calculate the averages, the Source variable or array to average, the data format (see Table 4.5-1) to store the result in, and a disable variable that allows excluding readings from the average if conditions
are not met. A reading will not be included in the average if the disable variable is not equal to 0. In the following program snippet, averages for the RefTemp variable, and the 6 elements of the TC() variable array are stored to the Data Table as a single record every 100 milliseconds.

When using an Output processing instruction like Average, the table should be called more frequently than Table output occurs so that more than one value will be included in the average computation.

For instance, in Example 4.2.8-4, the Table output rate is once every 100 milliseconds. If the Table is only called, using the CallTable instruction, once every 100 milliseconds, the computed average for each output would only use a single sample. But, if the Table were called once every 10 milliseconds, the average would be computed using 10 values.

EXAMPLE 4.2.8-4: CRBasic Code: Average Output Instruction
DataTable(Table1,True,2000)
DataInterval(0,100,msec,10)
CardOut(0,-1)
'Average(Reps, Source, DataType,
DisableVar)
Average(1,RefTemp,fp2,0)
Average(6,TC(1),fp2,0)
EndTable

新对话如下:

I have moved my question to a new thread:
Maximum/Average

@wlcable Please look there.

* Last updated by: Bo on 2/23/2010 @ 4:20 AM *

新对话如下:

TweedleDee-

This is very helpful. Thanks!

分享到:

原文链接:,转发请注明来源!
海洋仪器网 仪器使用 "Average" Function_Campbellsci论坛问答
「"Average" Function_Campbellsci论坛问答」评论列表

发表评论