Engee documentation

cusum

Detecting small changes in mathematical expectation using a cumulative sum.

Library

EngeeDSP

Syntax

Function call

  • iupper,ilower = cusum(x) — returns the first index of the upper and lower cumulative sums x, which deviated by more than five standard deviations up and down from the target mathematical expectation, respectively. The minimum detectable expectation offset is one standard deviation. The function evaluates the target mathematical expectation and standard deviations for the first 25 selections x.

  • iupper,ilower = cusum(x,climit,mshift,tmean,tdev) — determines the number of standard deviations climit by which the upper and lower cumulative sums may deviate from the mathematical expectation. This call also determines the minimum detectable expectation value offset, the target expectation value, and the target standard deviation.

  • iupper,ilower = cusum(___,"all") — returns all indexes where the upper and lower cumulative amounts exceed the control limit.

  • cusum(___) — without output arguments, builds the upper and lower cumulative sums normalized to one standard deviation above and below the target mathematical expectation.

Arguments

Input arguments

# x — input signal

+ vector

Details

The input signal is set as a vector.

# climit — control limit

+ 5 (by default) | the real scalar

Details

The reference limit, set as a real scalar, expressed in standard deviations.

# mshift — minimum expectation offset for detection

+ 1 (by default) | the real scalar

Details

The minimum expectation value offset for detection, given as a real scalar expressed in standard deviations.

# tmean — target mathematical expectation

+ mean(x[1:25]) (by default) | the real scalar

Details

The target mathematical expectation, set as a real scalar. If the argument is tmean not specified, it is estimated as the average value of the first 25 values x.

# tdev — target standard deviation

+ std(x[1:25]) (default) | the real scalar

Details

The target standard deviation, set as a real scalar. If the argument is tdev not specified, it is estimated as the standard deviation of the first 25 values x.

Name-value input arguments

# out — type of output data

+ :plot (by default) | :data

Details

Type of output data:

  • :plot — the function returns a graph;

  • :data — the function returns data.

Output arguments

# iupper, ilower — indexes of points beyond the control

+ integer scalars | integer vectors

Details

Indexes of points beyond the control, returned as integer scalars or vectors. If all samples of the signal are within the specified tolerance, the function cusum returns empty arguments iupper and ilower.

# uppersum, lowersum — upper and lower cumulative sums

+ vectors

Details

The upper and lower cumulative amounts returned as vectors.

Examples

Default values for the function cusum

Details

Let’s generate and build a graph 100-a selective random signal with a linear trend. To get reproducible results, reset the settings of the random number generator.

rnds = rand(1, 100)
trnd = range(0, 1, length=100)
fnc = rnds .+ trnd'

plot(vec(fnc))

cusum 1

Apply cusum to the function using the default values of the input arguments.

import EngeeDSP.Functions: cusum

cusum(fnc)

cusum 2

Let’s calculate the mathematical expectation and standard deviation for the former 25 samples. Apply cusum using these values as the target expectation and the target standard deviation. Let’s highlight the point at which the cumulative sum deviates by more than five standard deviations from the target mathematical expectation. Let’s set the minimum detectable expectation offset to one standard deviation.

import EngeeDSP.Functions: mean, std

mfnc = mean(fnc[1:25])
sfnc = std(fnc[1:25]).S

cusum(fnc, 5.0, 1.0, mfnc, sfnc)

cusum 3

Let’s repeat the calculation using a negative linear trend.

nnc = rnds .- trnd'

cusum(nnc)

cusum 4

Additional Info

CUSUM Control Chart

Details

The CUSUM control chart is designed to detect small increments in the mathematical expectation of a process.

The sequence is given with an estimated average and the estimated standard deviation . Determine the upper and lower cumulative amounts of the process using:

  • the upper cumulative amount

  • the lower amount

Variable , presented in cusum an argument mshift, is the number of standard deviations from the target mathematical expectation tmean which make the shift detectable.

The process violates the CUSUM test in the sample if it satisfies the condition or . The control limit presented in cusum an argument climit.

By default, the function returns the first detected violation. If the flag is specified "all", the function will return all violations.