Function find_peaks_zscore

Source
pub fn find_peaks_zscore(
    nanoseconds: &Vec<f32>,
    voltages: &Vec<f32>,
    start_time: f32,
    window_size: f32,
    lag: usize,
    threshold: f64,
    influence: f64,
) -> Result<Vec<(usize, usize)>, WaveformError>
Expand description

Z-scores peak finding algorithm

Brakel, J.P.G. van (2014). “Robust peak detection algorithm using z-scores”. Stack Overflow. Available at: https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data/i22640362#22640362 (version: 2020-11-08).

Robust peak detection algorithm (using z-scores)

[..] algorithm that works very well for these types of datasets. It is based on the principle of dispersion: if a new datapoint is a given x number of standard deviations away from a moving mean, the algorithm gives a signal. The algorithm is very robust because it constructs a separate moving mean and deviation, such that previous signals do not corrupt the signalling threshold for future signals. The sensitivity of the algorithm is therefore robust to previous signals.

§Arguments:

  • nanoseconds : calibrated waveform times
  • voltages : calibrated waveform voltages
  • start_time : restrict the algorithm on a certain time window, start at start_time
  • window_size : in ns
  • lag : The lag of the moving window that calculates the mean and standard deviation of historical data. A longer window takes more historical data in account. A shorter window is more adaptive, such that the algorithm will adapt to new information more quickly. For example, a lag of 5 will use the last 5 observations to smooth the data.
  • threshold : The “z-score” at which the algorithm signals. Simply put, if the distance between a new datapoint and the moving mean is larger than the threshold multiplied with the moving standard deviation of the data, the algorithm provides a signal. For example, a threshold of 3.5 will signal if a datapoint is 3.5 standard deviations away from the moving mean.
  • influence : The influence (between 0 and 1) of new signals on the calculation of the moving mean and moving standard deviation. For example, an influence parameter of 0.5 gives new signals half of the influence that normal datapoints have. Likewise, an influence of 0 ignores signals completely for recalculating the new threshold. An influence of 0 is therefore the most robust option (but assumes stationarity); putting the influence option at 1 is least robust. For non-stationary data, the influence option should therefore be put between 0 and 1.