packages

signal::peaks

On this page

Peak finding as SciPy's find_peaks: local maxima (a flat top counts once, at its middle), then filtered by height, by distance (highest first) and by topographic prominence.

Structs

PeaksSource

pub struct Peaks

The peaks find_peaks kept, in increasing position, with the properties it measured.

  • pub indices: Vector<usize>§

    Source

    Sample positions of the peaks.

  • pub heights: Vector<f64>§

    Source

    x at each peak.

  • pub prominences: Vector<f64>§

    Source

    How far each peak stands above the higher of its two bases.

  • pub left_bases: Vector<usize>§

    Source

    The lowest point between each peak and the next higher sample on its left (or the start).

  • pub right_bases: Vector<usize>§

    Source

    The same on the right.

  • pub fn len(self) -> usize§

    Source

    The number of peaks.

Functions

find_peaksSource

pub fn find_peaks(x: some RealSamples, height: f64? = none, distance: usize? = none, prominence: f64? = none) throws (SignalError) -> Peaks

The peaks of x: samples higher than both neighbours (a flat top counts once, at its middle; the ends never count). Then, each only when given: keep peaks at least height high; keep peaks at least distance samples apart, the highest first; keep peaks with prominence at least prominence. NaN samples are never peaks.

nabi
use core::array::Vector;

let x: Vector<f64> = [0, 2, 0, 1, 0, 3, 3, 0, 1, 0];
let p = try signal::find_peaks(x);
println(p.indices); // [1, 3, 5, 8]
let tall = try signal::find_peaks(x, height: 1.5, distance: 2);
println(tall.indices); // [1, 5]
println(tall.prominences); // [2.0, 3.0]