Skip to main content

PeakFinder

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Module

This page documents a header-level module — a collection of free functions that share an algorithmic topic. There is no enclosing C++ class; the functions live directly in the library namespace.

Python equivalent

mne.preprocessing.peak_finder in MNE-Python.

#include <dsp/peak_finder.h>

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors.

A peak is defined as a sample that is strictly larger than its two direct neighbours. The basic detector locates every such sample in linear time; three classical post-filters then prune the candidate list:

  • a minimum height (absolute amplitude floor),
  • a minimum inter-peak distance in samples (suppressing close-by peaks by retaining only the tallest within the exclusion window), and
  • a minimum topographic prominence — the height by which a peak rises above the higher of the two adjacent valleys, computed in the same way as scipy.signal.peak_prominences.

The API mirrors scipy.signal.find_peaks closely so MEG/EEG analysis pipelines that already rely on SciPy semantics (cHPI peak picking, ECG R-wave detection, event onset extraction) port to mne-cpp without behavioural drift.

src/examples/ex_dsp_analysis/main.cpp
PeakFinderParams params;
params.dMinHeight = 0.5; // like scipy.signal.find_peaks(height=0.5, distance=30)
params.iMinDistance = 30;
const QList<QPair<int, double>> peaks = peakFinder(wave, params); // (sample, value), sorted by sample
const VectorXd prominence = peakProminences(wave, {2, 9, 15});

Functions​

peakFinder(data, params)​

QList< QPair< int, double > > peakFinder(const Eigen::VectorXd & data, const [PeakFinderParams](/docs/api/dsp/peak-finder-params) & params);

Find peaks in a 1D signal.

A peak is a sample that is strictly greater than both its neighbours. Additional filtering by height, distance, and prominence can be applied.

Parameters:

  • data : const Eigen::VectorXd & 1D signal (row vector or VectorXd).

  • params : const PeakFinderParams & Peak detection parameters.

Returns:

  • QList< QPair< int, double > > — List of (peak_index, peak_value) pairs, sorted by index.

peakProminences(data, peakIndices)​

Eigen::VectorXd peakProminences(const Eigen::VectorXd & data, const QList< int > & peakIndices);

Compute prominence of each peak.

Prominence is the vertical distance from a peak to the highest valley on either side before reaching a higher peak.

Parameters:

  • data : const Eigen::VectorXd & 1D signal.

  • peakIndices : const QList< int > & Indices of detected peaks.

Returns:

  • Eigen::VectorXd — Prominence value for each peak.

peakFinderMne(data, thresh, extrema)​

QList< QPair< int, double > > peakFinderMne(const Eigen::VectorXd & data, double thresh, int extrema);

Noise-tolerant extrema search of mne.preprocessing.peak_finder.

A peak must rise at least thresh above the minimum to its left and fall at least thresh before the next one counts; the end points are candidates too.

Parameters:

  • data : const Eigen::VectorXd & Non-empty 1D signal.

  • thresh : double Required rise/fall; NaN = (max - min) / 4.

  • extrema : int 1 for maxima, -1 for minima.

Returns:

  • QList< QPair< int, double > > — List of (peak_index, peak_value) pairs, sorted by index.

Example​

Authors of this file​