Home > OS >  Why is find_peaks() not working correctly for determining highest peaks of a waveform?
Why is find_peaks() not working correctly for determining highest peaks of a waveform?

Time:03-15

I am trying to replicate the MATLAB function findpeaks() in Python using find_peaks() from scipy.signal.

Basically I'm trying to translate the MATLAB example enter image description here

I can't figure out why find_peaks() is working fine the 1st time (when all peaks are determined) but fails to give the correct results the 2nd time when more arguments are provided to find the highest peaks.

How can I detect the highest peaks of the 2nd period correctly?

CodePudding user response:

I'm answering my own question.

I realized that the only mistake I was doing in my Python code was not normalizing the autocorr values as was done in the Matlab example. I simply added the following in my code:

autocorr = (autocorr-min(autocorr))/(max(autocorr)-min(autocorr))

When I do so, I eventually get the desired results, same as that in the example: enter image description here

Hence, to conclude, find_peaks() does in fact do the intended job.

  • Related