Reputation: 165
I have a simple problem where I need to find the peaks of a waveform. Now, I have done this before using the find_peaks_cwt method from the scipy library. However, in this case my program simply hangs while attempting to find the peaks. I am thinking that this has to do with either the number of samples in the waveform or the "widths" argument that I am using.
After downsampling the signal I was able to find the peaks properly, however, it took a VERY long time to find them. About five minutes.
Here is a screenshot of the waveform.
The waveform has 526728 samples. I don't think this is such a complicated task where I'd be running out of hardware resources (memory, CPU, etc)
Here is a screenshot of a waveform that I got it to work on using the code:
iMaxPeaks = signal.find_peaks_cwt(signal, np.arange(35,40), min_snr=2)
This wave contains 32000 samples.
Any help or a pointer in the right direction is greatly appreciated.
Upvotes: 1
Views: 1527
Reputation: 25518
From the docs for: find_peaks_cwt
scipy.signal.find_peaks_cwt(vector, widths, wavelet=None, max_distances=None, gap_thresh=None, min_length=None, min_snr=1, noise_perc=10)[source]
Attempt to find the peaks in a 1-D array.
The general approach is to smooth vector by convolving it with wavelet(width) for each width in widths. Relative maxima which appear at enough length scales, and with sufficiently high SNR, are accepted.
This convolution (for each of 5 widths) is likely to be what's causing your code to take a long time to run. Looking through the source, find_peaks_cwt
calls cwt
which calls scipy.signal.convolve
: this method does not seem to use the FFT method for convolution which might be expected to be faster for large arrays.
If you can reimplement the convolution using FFT, you might see an improvement in performance. (The number of your samples, 526728, is just over 2^19. If you were to get by with 2^19 = 524288 samples it would be faster still).
To see if you are running into memory limitations, you could try ramping up the sample size slowly and see if there's a critical size at which performance drops off dramatically.
Upvotes: 2