Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Peak Detection in Python: How does the scipy.signal.find_peaks_cwt function work?

I'm looking to identify some peaks in some spectrograph data, and was trying to use the scipy.signal.find_peaks_cwt() function to do it.

However, the official documentation I've found isn't too descriptive, and tends to pick up false peaks in noise while sometimes not picking up actual peaks in the data.

Could anyone give me a better explanation of the parameters in this function that I can play with, including "widths", or could you show me some alternatives?

like image 644
NGXII Avatar asked Jun 24 '15 01:06

NGXII


People also ask

How does SciPy signal Find_peaks work?

The Python Scipy has a method find_peaks() within a module scipy. signal that returns all the peaks based on given peak properties. Peaks are not merely the peaks of an electric signal, maxima and minima in a mathematical function are also considered peaks.

How do you find peaks on SciPy?

Find peaks using the wavelet transformation. Directly calculate the prominence of peaks. Directly calculate the width of peaks. In the context of this function, a peak or local maximum is defined as any sample whose two direct neighbours have a smaller amplitude.

What is prominence in SciPy find peaks?

The prominence of a peak measures how much a peak stands out from the surrounding baseline of the signal and is defined as the vertical distance between the peak and its lowest contour line.


1 Answers

If your signal is relatively clean, I suggest first using simpler alternatives, like the PeakUtils indexes function. The code is way more direct than with scipy.signal.find_peaks_cwt:

import numpy as np
from peakutils.peak import indexes
vector = [ 0, 6, 25, 20, 15, 8, 15, 6, 0, 6, 0, -5, -15, -3, 4, 10, 8, 13, 8, 10, 3, 1, 20, 7, 3, 0 ]
print('Detect peaks with minimum height and distance filters.')
indexes = indexes(np.array(vector), thres=7.0/max(vector), min_dist=2)
print('Peaks are: %s' % (indexes))

enter image description here

The Scipy find_peaks_cwt will really prove usefull in presence of noisy data, as it uses continuous wavelet transform.

like image 67
Yoan Tournade Avatar answered Oct 17 '22 03:10

Yoan Tournade