kkk
kkk

Reputation: 1920

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

Upvotes: 6

Views: 7321

Answers (1)

Bob Baxley
Bob Baxley

Reputation: 3751

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.

Upvotes: 5

Related Questions