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.

3 Second Running Average Wspd Wdir Std_Dev Wdir


wx2day Nov 27, 2013 05:58 PM

Trying to code a 3-sec running average of Wind Speed, Wind Directrion and Standard Deviation of Wind Direction updated every second and store in a 1-sec table.

Here is code:
SequentialMode
PreserveVariables
'Declare Public Variables
Public Wspd,Wdir, MeanWspd, MeanWdir
'Declare Units
Units Wspd = m/sec
Units Wdir= deg
Units MeanWspd=m/s
Units MeanWdir=deg

'Define Data Tables
DataTable (TB1Sec,True,-1)
DataInterval (0,1,Sec,10)
WindVector (1,Wspd,Wdir,FP2,False,0,0,0)
FieldNames("WindSpeed_S_WVT,WD_D1_WVT,WD_SD1_WVT")
Sample (1,MeanWdir,FP2)
Maximum (1,Wspd,FP2,False,False)
EndTable

'Main Program
BeginProg


Scan (1,Sec,0,0)
'Measure the 05103 Wind Speed & Direction Sensor measurements WS_ms and WindDir:
PulseCount(Wspd,1,2,1,1,0.098,0)
BrHalf(Wdir,1,mV2500,10,2,1,2500,True,0,_60Hz,355,0)
Wspd=5
If Wspd= 0 Then Wdir = 0 'Calm Condition
If Wspd > .098 AND Wdir <=0 OR Wdir >360 Then Wdir = 360 'Sets Reading to 360 when Ws is occurring and Wd<=0 OR Wd>360 deg
If Wspd >.098 AND Wdir >354.9 AND Wdir < 360 Then Wdir = 360 'Sets Reading to 360 when Ws is present for Wd>354.9 AND Wd<360 deg
AvgRun (MeanWspd,1,Wspd,3)
AvgRun (MeanWdir,1,Wdir,3)
CallTable (TB1Sec)


NextScan
EndProg

Will this accomplish it?
I'm using avgRun function. Is there another way to accomplish this w/o using this function?
Thanks,
wx2day


peterparker Sep 29, 2014 01:43 PM

You can't just average wind directions. For example, the average 359 and 1 is 180, but when it comes to wind it should be 0. So you have to average the x and y components of wind direction and then reconstruct the average wind direction.

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