.find_peaks()
Published Jan 18, 2025
Contribute to Docs
In SciPy, the .find_peaks()
function identifies the indices of local maxima (peaks) in a 1D signal array based on specified conditions.
Syntax
scipy.signal.find_peaks(x, height=None, threshold=None, distance=None, prominence=None, width=None, wlen=None, rel_height=0.5, plateau_size=None)
x
: The input data in which to search for peaks.height
(Optional): Specifies the required height of peaks.threshold
(Optional): The vertical distance to the neighboring samples.distance
(Optional): Minimum horizontal distance (in samples) between neighboring peaks.prominence
(Optional): Minimum prominence of peaks.width
(Optional): Required width of peaks in samples.wlen
(Optional): Used for calculating the prominence of peaks; specifies the size of the window.rel_height
(Otional): Used for measuring the width at relative height.plateau_size
(Optional): Specifies the size of flat peaks (plateaus).
Example
The following example showcases the .find_peaks()
function:
import numpy as npfrom scipy.signal import find_peaks# Create a signal with some peakssignal = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1])# Find the peaks in the signalpeaks, _ = find_peaks(signal)# Print the indices of the peaksprint(peaks)
The code above generates the following output:
[4]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SciPy on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours