Nazim Kerimbekov
Nazim Kerimbekov

Reputation: 4783

how to find troughs in a 1-D array

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

Upvotes: 6

Views: 9836

Answers (3)

user8017857
user8017857

Reputation:

only to print peaks

peaks = find_peaks(x)
peak = peaks[1]['peak_heights'] 
print(peak)

Upvotes: -1

coremonkey
coremonkey

Reputation: 81

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()

Upvotes: 4

Imperishable Night
Imperishable Night

Reputation: 1533

Is scipy.signal.find_peaks(-x) what you need?

Upvotes: 17

Related Questions