MovingStatistics

A processing block for calculating moving statistics of a signal and detecting anomalies based on dynamically caluclated thresholds.

The moving statistic processing block can be found in the ‘Templates’ feature in the PMP installer.

Description

The top level routing of the processing block is shown in MovingStatistics processing block routing.

movingstatistics  implementation

MovingStatistics processing block routing

Exponentially Weighted Statistics

The mean value, variance and standard deviation of a signal are calculated via an exponentially weighted moving average filter.

\[Mean_n = \alpha \ X_n + (1 - \alpha) Mean_{n-1}\]
\[Variance_n = (1 - \alpha)(Variance_{n-1} + \alpha(X_n - Mean_{n-1})^2)\]
\[StandardDeviation_n = \sqrt{Variance_n}\]

The smoothing of the filter can be adjusted via the smoothing factor signal \(\alpha\), with \(0 < \alpha < 1\). A lower \(\alpha\) value provides more filtering, and thus a smoother mean value. The smoothing factor is typically calculated from the desired time constant \(\tau\). The time constant is defined as the amount of time for the mean to reach approximately 63.2% of the original signal value after a step reponse. The relation between the time constant and smoothing factor is:

\[\alpha \approx \frac{SamplePeriod}{\tau}\]

The initial condition for the variance is \(Variance_0 = X_0^2 / (1 - \alpha)\) in order to prevent false positives during start.

Threshold Detection

The upper and lower threshold for detecting anomalies are automatically determined based on the mean value and standard deviation of the signal. The thresholds can be modified via the tolerance signal:

\[ \begin{align}\begin{aligned}UpperThreshold = Mean + StandardDeviation \times Tolerance\\LowerThreshold = Mean - StandardDeviation \times Tolerance\end{aligned}\end{align} \]

When the signal value exceeds the upper or lower threshold the ThresholdExceeded event is triggered. The ThresholdExceededCount signal is raised by 1 for each sample the ThresholdExceeded event is active. The ThresholdExceededCount can be reset via the ThresholdExceededCountReset signal.

Interface

Inputs

Inputs

Name

Description

X

Signal to be monitored.

Read only signals

Read only signals

Name

Description

Mean

Exponentially weighted moving mean of X.

Variance

Exponentially weighted moving variance of X.

StandardDeviation

Exponentially weighted moving standard deviation of X.

UpperThreshold

Upper threshold for ThresholdExceeeded detection.

LowerThreshold

Lower threshold for ThresholdExceeeded detection.

ThresholdExceededCount

Number of samples the upper or lower threshold is exceeded since last reset.

Read-write signals

Read-write signals

Name

Description

Alpha

Exponential weight factor.

Tolerance

Number of standard deviations tolerance for determinining the upper and lower threshold.

ThresholdExceededCountReset

Reset threshold exceeded counter.

Events

Events

Name

Description

ThresholdExceeded

Signal value not between UpperThreshold and LowerThreshold.