7 Replies Latest reply on Oct 4, 2011 6:06 PM by Ahmad Fattahi

# Time weighted Standard Deviation

I am trying to calculate time weighted standard deviation on  PI data. I am using formula below.  My time weighted average result matches the PI summary average but not the standard deviation.

Is Pi using any different way for standard deviation calculations. • ###### Re: Time weighted Standard Deviation

Hi Priyanka,

Sorry, this post of yours "fell among the cracks".

Could you tell us which PI products you are using to calculate the time-weighted standard deviation? Are you coding using the PI-SDK? Or maybe PI DataLink? Please let us know.

• ###### Re: Time weighted Standard Deviation

Hi Daniel,

I am using PI SDK for coding. But instead of making summary call for time-weighted standard deviation I want to calculate it manually in the code. I am currently using above formula for calculation. But results is different than PI standard deviation summary call(datalink).

Thank you.

• ###### Re: Time weighted Standard Deviation

Thanks Priyanka!

Just wanted to let you know that I am looking into this and will provide you soon with an explanation of the algorithm utilized by the PI-SDK.

• ###### Re: Time weighted Standard Deviation

Thank you Daniel.

• ###### Re: Time weighted Standard Deviation

Sorry for the delay Priyanka. When it comes to standard deviation, the PI Server (as opposed to PI SDK) calculates a time-weighted standard deviation.
Given a start time T0 and an end time Tn, and a sequence of archive values (Y0, Y1, Y2,  ... , Yn) at times (T0, T1, T2, ..., Tn), respectively, we have the following formula:

StandardDeviation = SQRT ( Variance )

Variance  =  V / ( 3 * time)  -  ( ( W / time ) ^ 2 ) / 4

time = Tn – T0

V = Sum [for  i=1 to n ] of ( ( Ti – T(i-1) ) * ( Yi ^ 2 + Y(i-1) ^ 2 + Yi * Y(i-1) ) )

W = Sum [for  i=1 to n ] of ( ( Ti – T(i-1) ) * ( Yi + Y(i-1) ) )

The above is for when the step attribute for the point is 0.  When the step attribute is 1, the only difference in the above are V and W, which simplify to the following (because Yi = Y(i-1)):

V = Sum [for  i=1 to n ] of ( ( Ti – T(i-1) ) * 3 * Y(i-1) ^ 2 )

W = Sum [for  i=1 to n ] of ( ( Ti – T(i-1) ) * 2 * Y(i-1) )

Note that we do some other minor things like subtract each value from the first good value (= not a system digital state) in an attempt to reduce mathematical error (adding / subtracting a constant does not change the variance) and only consider good time.