0

I want to find the location of the maximum peak how can I do it? I am using scipy.signal for finding peaks. I want the code to return the location (in ums) for the peak.

enter image description here

1
  • 2
    if your data is stored in a numpy array, just use np.argmax. Eg: data = np.array([1,2,6,3,2]) np.argmax(data) -> 2 (which is the location of the maximum element: 6)` Commented Jun 9, 2022 at 10:11

1 Answer 1

5

If you want to find the highest of the peaks identified by scipy.signal.find_peaks then you can do the following:

import numpy as np
from scipy.signal import find_peaks
import matplotlib.pyplot as plt

# Example data
x = np.linspace(-4000, 4000)  # equal spacing needed for find_peaks
y = np.sin(x / 1000) + 0.1 * np.random.rand(*x.shape)

# Find peaks
i_peaks, _ = find_peaks(y)

# Find the index from the maximum peak
i_max_peak = i_peaks[np.argmax(y[i_peaks])]

# Find the x value from that index
x_max = x[i_max_peak]

# Plot the figure
plt.plot(x, y)
plt.plot(x[i_peaks], y[i_peaks], 'x')
plt.axvline(x=x_max, ls='--', color="k")
plt.show()

enter image description here

If you just want the highest point then do just use argmax as Sembei suggests.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.