Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scipy.signal.find_peaks_cwt parameters

I am building a heart rate monitor , after smoothing the points I want to find the find the number of peaks present in the graph and thus i want to use the method scipy.signal.find_peaks_cwt() to find the peaks but i am not able to understand as what parameters should i pass as the documentation present in the scipy.org is not good.

http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks_cwt.html#scipy-signal-find-peaks-cwt

I have taken a 10 second video of the finger with the flash on , The heart rate may vary from 40bpm to 200bpm.

scipy.signal.find_peaks_cwt(vector, widths, wavelet=None, max_distances=None, gap_thresh=None, min_length=None, min_snr=1, noise_perc=10)

I am really confused as what the width parameter is , any help would be great. Thanks in advance

like image 504
kkk Avatar asked Dec 30 '15 17:12

kkk


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 the peak value in Python?

Practical Data Science using Python Suppose we have an input array nums, where nums[i] ≠ nums[i+1], search for a peak element and return its index. The array can hold multiple peak elements, in that case return the index to any one of the peak elements. We can imagine that nums[-1] = nums[n] = -∞.

What does Argrelextrema do?

Calculate the relative extrema of data. Array in which to find the relative extrema. Function to use to compare two data points.


1 Answers

You can think of the widths argument as a list of the possible widths between peaks. The algorithm smooths over these widths and then look for a peak. if it consistently finds a peak in each "width", it declares that the peak exists.

# sample rate
fs = 100.0

# time vector (10s)
t = np.arange(0,10,1/fs)

# heart rates to test
rates = np.array([40,80,100,150,200])/60  

# create periodic signal that looks a  little like a heartbeat
signal = abs(np.sin(t*np.pi*rates[2])**3)

#add noise
signal_w_noise = signal + np.random.randn(len(signal))*0.1
plt.plot(t,signal_w_noise)

#find peaks
peaks = scipy.signal.find_peaks_cwt(signal_w_noise, fs/rates/10)
plt.plot(t[peaks],signal_w_noise[peaks],'ro')

enter image description here

fs/rates/10 are the widths I used. Notice that they correspond to the number of samples expected between peaks. That is, fs/rates is the number of samples between peaks. You might need to twiddle with the factor of 1/10 to get better results.

like image 53
Bob Baxley Avatar answered Oct 07 '22 20:10

Bob Baxley