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.

"Intermediary" average?


Vigon Sep 9, 2011 09:53 AM

Hello,

I'm trying to re-write a program for the CR1000 coming from a CR10X and have some troubles to create an intermediary average.

To explain my problem, here is synthetically what my program must do :
1: take measures (diffVolt) every 5 seconds.
2: average one of these measures every minute and make some calculations with this "intermediary average"
3: average the results of point 2 every 10 minutes and store it in a table

You aren't obviously not expected to write my program but could you tell me what to do?

Here is my program in its current version : (PS : my tables are stored every 5s for now, I know it)


'CR1000

'Declare Variables and Units
Public BattV
Public CSD3_DiffV(2)
Public CSD3_SYN_B_5s
Public CNR1_Trad_V_5s
Public CNR1_Trad_DegC_5s
Public CNR1_DiffV(4)

Alias CSD3_DiffV(1)=CSD3_SYN_V_5s
Alias CSD3_DiffV(2)=CSD3_SI_W_5s
Alias CNR1_DiffV(1)=CNR1_LwUE_V_5s
Alias CNR1_DiffV(2)=CNR1_LwDE_V_5s
Alias CNR1_DiffV(3)=CNR1_SwG_V_5s
Alias CNR1_DiffV(4)=CNR1_SwR_V_5s

Units BattV=Volts
Units CNR1_Trad_V_5s=mV/V
Units CSD3_SYN_V_5s=mV
Units CSD3_SI_W_5s=mV
Units CNR1_LwUE_V_5s=mV
Units CNR1_LwDE_V_5s=mV
Units CNR1_SwG_V_5s=mV
Units CNR1_SwR_V_5s=mV

'Define Data Tables
DataTable(CSD3,True,-1)
' DataInterval(0,10,Min,10)
Average(1,CSD3_SYN_B_5s,FP2,False)
Average(1,CSD3_SI_W_5s,FP2,False)
EndTable

DataTable(CNR1,True,-1)
Average(1,CNR1_Trad_DegC_5s,FP2,False)
Average(1,CNR1_LwUE_V_5s,FP2,False)
Average(1,CNR1_LwDE_V_5s,FP2,False)
Average(1,CNR1_SwG_V_5s,FP2,False)
Average(1,CNR1_SwR_V_5s,FP2,False)
EndTable

DataTable(Battery_Control,True,-1)
DataInterval(0,1440,Min,10)
Minimum(1,BattV,FP2,False,False)
EndTable

'Main Program
BeginProg
Scan(5,Sec,1,0)
'Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Differential Voltage measurements of CSD3_DiffV()
VoltDiff(CSD3_DiffV(),2,mV2500,1,True,0,_50Hz,1,0)
'4 Wire measurements CNR1_Trad_V_5s of Pt100 CNR1
BrHalf4W(CNR1_Trad_V_5s,1,mV25,mV25,3,Vx1,1,2200,True,True,0,_50Hz,1,0)
'Convert Trad from mV/V to Celcius degrees
PRTCalc(CNR1_Trad_DegC_5s,1,CNR1_Trad_V_5s,1,1.0,0)
'Differential Voltage measurements of CNR1_DiffV()
VoltDiff(CNR1_DiffV(),4,AutoRange,5,True,0,_50Hz,1,0)

'Transform CSD3 Sunshine DiffVoltage (mV) to Boolean (1/0)
If (CSD3_SYN_V_5s > 500) Then
CSD3_SYN_B_5s = 1
Else
CSD3_SYN_B_5s = 0
EndIf

'Every minute, make an average of CNR1 Temperature and the radiance calculus
If (IfTime (0,1,Min)) Then
Tavg = Average(1,CNR1_Trad_DegC_5s,FP2,False)
EndIf

'Call Data Tables and Store Data
CallTable(CSD3)
CallTable(CNR1)
CallTable(Battery_Control)
NextScan
EndProg


Vigon Sep 9, 2011 09:56 AM

*you aren't obviously expected...* - sorry for my poor english :)


aps Sep 9, 2011 10:03 AM

There are two ways of doing this:

a) if this is just for one or two values and the average time is not too long, use the AvgRun instruction, which does a "block" running average. In your case the number values to average is 12 (one minute of 5 sec values). One advantage of this using this instruction is you can see the running average all the time, which is useful sometimes.

b) create a special datatable which is used just to store one minute statistics (it need only have one record in it). You call the table as normal containing the average instruction or whatever. Then after it has been called to store data, you can get the averages in the table back into normal variables using the Tablename.Fieldname syntax (search for that in the help).

* Last updated by: aps on 9/9/2011 @ 4:04 AM *


Sam Sep 9, 2011 02:47 PM

The following might be some examples of methods A and B above


Public A, A_Avg, B
DataTable (Test,1,1000)
DataInterval (0,10,Min,10)
Average(1,B,FP2,False)
EndTable
BeginProg
Scan(5,Sec,0,0)
PanelTemp (A,250)
AvgRun(A_Avg,1,A,12)
If TimeIntoInterval (0,60,Sec) Then
B = A_Avg * 1.8 + 32
CallTable (Test)
EndIf
NextScan
EndProg

-----------------------

Public A, B
DataTable (Test,1,1000)
DataInterval (0,10,Min,10)
Average(1,B,FP2,False)
EndTable
DataTable(Inter,1,10)
DataInterval (0,1,Min,10)
Average(1,A,FP2,False)
EndTable
BeginProg
Scan (5,Sec,0,0)
PanelTemp (A,250)
CallTable Intermediary
If Inter.Output Then
B = Inter.A_Avg * 1.8 + 32
CallTable (Test)
EndIf
NextScan
EndProg

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