StdDevRun (Running Standard Deviation)

The StdDevRun instruction is used to output the running standard deviation of a measurement. This instruction is available in Operating Systems 7.0 and later.

Syntax

StdDevRun ( Dest, Reps, Source, Number, RunReset [optional] , Count [optional] TotalCalls [optional], Call_ID [optional], StdDevType [optional])

Remarks

This instruction, when used, must appear between the Scan … NextScan instructions. A running standard deviation is the standard deviation of the last N values where N is specified in the Number argument. Until the data logger has taken N measurements the standard deviation is calculated based on the number of actual measurements made.

The running standard deviation is calculated from the non-ClosedNAN Not a number. A data word indicating a measurement or processing error. Voltage overrange, SDI-12 sensor error, and undefined mathematical results can produce NAN. values in the buffer of historical data. In the event that all values in the buffer are NAN, the output will be 0. The StdDevRun instruction should be called conditionally (only when good values are received) to avoid NAN values affecting the output. When called conditionally, the standard deviation is calculated as the standard deviation of the last number of good values.

Parameters

Dest (Destination)

The Variable in which to store the results of the instruction. Right-click the parameter to display a list of defined variables.

If this instruction has a Repetitions parameter and it is greater than 1, the results are stored in an array with the variable name. The array must be dimensioned large enough to hold all of the values returned from all of the Reps.

Type: Variable or Array

Reps (Repetitions)

The number of repetitions for the measurement or instruction.

Type: Constant integer (or expression that evaluates as a constant).

For the StdDevRun instruction, the Reps parameter is the number of variables in the array for which a running standard deviation should be calculated. When the Source is not an array, or only a single variable in the array should be used, Reps should be 1.

Source

The name of the Variable that is the input for the instruction. Right-click the parameter to display a list of defined variables.

Type: Variable

Number

The number of values of Source to be used for calculating the running average, running total, running minimum, running maximum, or running standard deviation.

Type: Constant (or expression that evaluates as a constant)

Optional Parameters

RunReset

When RunReset is true, the history over which the running value (for example, running average, running maximum, running minimum, running total, or running standard deviation)  is calculated is cleared, so that the value returned is calculated from a a single value, the current input. Note that the reset parameter does not automatically toggle back to false once set to true. When the reset parameter is set back to false (problematically or manually), then the running average, running maximum, running minimum, or running total continues, starting with the current input. Note that until the data logger has taken N measurements, the running average/total/maximum/minimum is calculated based on the actual number of measurements made since reset was set back to false.

Type: ClosedBoolean Data type used to represent conditions or hardware that have only two states (true or false) such as flags and control ports. variable or expression that evaluates true/false

The TotalCalls and Call_ID optional parameters below, allow a single instance of the instruction (AvgRun, MaxRun, MinRun, StdDevRun) to be called with different source variables, as in a subroutine or function. Click here for additional information. These parameters are available with operating system 7 and later.

TotalCalls

Optional parameter that specifies the total number of calls to a specific instance of the instruction (AvgRun, MaxRun, MinRun, StdDevRun) in the program.

Type: Constant integer

Call_ID

Specifies a unique ID number for each specific call of the instruction.

Type: Integer

NOTE: If more than one instance of the instruction occurs in the program, each instance requires its own set of TotalCalls and Call_ID parameters.

Count

Optional parameter added in OS 3.02 and greater that returns the actual number of values used to calculate the running value. The actual number of values used may be different than the number specified for the calculation due to NAN values in the buffer of historical data. The Count parameter can only be used if the optional Reset parameter is also used. The Count parameter is a variable of Type Long and must be the same dimension as the array that is being averaged (i.e., the same as reps). A count used for each rep will be written to this variable on each execution of the instruction.

StdDevType

Optional parameter added in OS 8.00 and newer. Set this option to 1 to calculate a sample standard deviation instead of the default population standard deviation. The sample standard deviation uses a divisor of N−1, while the population standard deviation uses a divisor of N. A population standard deviation is used when you have data for the entire population. A sample standard deviation is used when you have data from a sample, not the entire population.

The following equation is used to calculate the default, population StdDev:

In contrast, the formula for the sample standard deviation is:

Note: the preceding optional parameters (RunReset, Count, TotalCall, and Call_ID) must be set in order to use the StdDevType option. The Reset parameter should be 0 (false), Count (N), should be a variable destination,TotalCall is 1, and Call_ID is any user-specified integer. See TotalCalls Call_ID for more information.See the Sample Standard Deviation example program for correct syntax.

 

NOTE: This instruction uses Closedhigh precision math A normal single precision float has 24 bits of mantissa. With high precision, a 32 bit extension of the mantissa is saved and used internally, resulting in 56 bits of precision. Instructions that use high precision are Average, AvgRun, AvgSpa, CovSpa, MovePrecise, RMSSpa, StdDev, StdDevSpa, TotalRun, and Totalize.. A normal single precision float has 24 bits of mantissa. With high precision, a 32 bit extension of the mantissa is saved and used internally, resulting in 56 bits of precision. Instructions that use high precision are AddPrecise, Average, AvgRun, AvgSpa, CovSpa, MinRun, MaxRun, MovePrecise, RMSSpa, StdDev, StdDevRun, StdDevSpa, TotalRun, and Totalize.