Does anyone know of a way to average wind direction in RTMC? I would like to be able to average five minutes worth of one minute data without creating a value in the datalogger program? An expression like WindVector("Server:CR10X.101.Wind_Dir",5) would be mighty handy, but there isn't one. I've tried to think of a way to write an expression which converts each one minute datapoint into a radian, takes the sine and cosine of each, averages these sines and cosines of the past five minutes, uses ATAN2 to turn that back into a wind direction in radians, coverts that back into degrees, and finally runs an IF statement to add 360 if the result is negative. If this is possible, so far I haven't figured out how to do it.
For a simple running avg you can do this...
StartRelativeToNewest(5*nSecPerMin, OrderCollected); Alias(W, "Server:CR1000.MINUTE.Wind_Deg"); AvgRunOverTime(W, Timestamp(W), 4 * nSecPerMin)
For Wind Vector Average this should work ...
StartRelativeToNewest(5 * nSecPerMin, OrderCollected); Alias(W, "Server:CR1000.MINUTE.Wind_Deg"); IIF((ATN2(AvgRunOverTime(sin(W * PI/180), Timestamp(W), 4 * nSecPerMin), AvgRunOverTime(cos(W * PI/180), Timestamp(W), 4 * nSecPerMin)) * 180 / PI) > 0, (ATN2(AvgRunOverTime(sin(W * PI/180), Timestamp(W), 4 * nSecPerMin), AvgRunOverTime(cos(W * PI/180), Timestamp(W), 4 * nSecPerMin)) * 180 / PI), 360 + (ATN2(AvgRunOverTime(sin(W * PI/180), Timestamp(W), 4 * nSecPerMin), AvgRunOverTime(cos(W * PI/180), Timestamp(W), 4 * nSecPerMin)) * 180 / PI))
* Last updated by: tmecham on 12/14/2010 @ 10:15 AM *
Thanks tmecham, that wind vector average is exactly what I'm looking for. I assume the simple average would get screwy when the wind is blowing out of the North. Could you explain why you use 5 minutes for the StartRelativeToNewest, but only 4 minutes for the rest of the expression?
Yes, the simple average gets messed up by the North value.
The AverageRunOverTime is a closed closed interval or [CurrentTime - interval, CurrentTime]. So if you specify 5 minutes in the AverageRunOverTime, you end up with 6 data points. If you want the AverageRunOverTime to be based on 5 data points, then the 4 minute interval takes care of this.