I've looked around StackOverflow and I noticed that a lot of the question are focused about finding peaks (not so many on finding the troughs). As of right now In order to find peaks, I'm using:
scipy.signal.find_peaks()
Which output the peaks and their index. That being said I'm wondering if there is anything similar to this function to find the troughs.
Thank you very much for your help
Is scipy.signal.find_peaks(-x)
what you need?
A quick example. That expands on the sample code in https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks.html#scipy.signal.find_peaks
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
from scipy.signal import find_peaks
x = electrocardiogram()[200:300]
peaks, _= find_peaks(x)
troughs, _= find_peaks(-x)
plt.plot(x)
plt.plot(peaks,x[peaks], '^')
plt.plot(troughs,x[troughs], 'v')
plt.show()
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