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
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.
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] = -∞.
Calculate the relative extrema of data. Array in which to find the relative extrema. Function to use to compare two data points.
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')
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With