Explanation of signal.find_peaks() approach

Question:

I have looked through the scipy.signal docs for an explanation of the peak finding approach used in find_peaks() and have been unable to find an explanation similar to the excellent explanation given but the cwt peak finding approach.

Is anyone here able to explain the peak finding approach used by the find_peaks() function

I am looking for a explanation specifically of the algorithmic implementation of the function as opposed to an explanation of it’s usage

Asked By: j1ling67n

||

Answers:

The documentation
has a Show Source link which reveals:

https://github.com/scipy/scipy/blob/v1.10.1/scipy/signal/_peak_finding.py#L835

a peak or local maximum is defined as any sample whose two direct neighbours have a smaller amplitude.

and it goes on to gather the raw features from this routine:

https://github.com/scipy/scipy/blob/v1.10.1/scipy/signal/_peak_finding_utils.pyx#L64

Likely you will want to run Gaussian blurring
over your noisy data, or windowed median or some other
technique prior to asking for peaks.
Or follow their advice to prefer find_peaks_cwt.

The documentation includes some nice illustrations
of how different parameter settings will change
the number of spurious detected peaks according
to your data’s pattern. Mostly we’re putting a simple box
around each candidate peak to see if it should
survive the filtering step.
Read the (short!) corresponding if clause
for each diagram which isn’t immediately clear.

Think about adding np.random.uniform(high=a) to b * sine_wave.
Depending on the magnitudes of a and b you might find
peaks at nearly every 2π interval. Or you might find a
multitude of local maxima within a single half-wave.
So smoothing will strongly affect peak detection performance.

Consider using this approach:

  1. For some window of samples, find the peak-to-peak amplitude — it will be 2.0 for pure sin(), more for noisy sin().
  2. Pick some threshold fraction of amplitude, perhaps 80%.
  3. Set all samples below threshold to minimum value.
  4. Do peak detection on this (much simpler) dataset.
Answered By: J_H
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.