Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Data Analysis

How to Use SciPy’s find_peaks to Find Peaks in a Signal

By Freedom251 Team · · 4 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

scipy.signal.find_peaks locates local maxima in a one-dimensional sampled signal and can filter them by amplitude, spacing, prominence, width, or flat-top size. Its output locations are sample indices—not timestamps—so choose conditions in the right units and map the results to your signal’s time axis when needed.

What SciPy’s find_peaks returns

The function compares neighboring samples to identify local maxima. A sample qualifies when its two direct neighbors have lower values. For a flat-topped peak, SciPy returns the middle sample; if the plateau has an even number of samples, it returns the middle position rounded down. See the SciPy 1.17.0 find_peaks documentation.

As an Amazon Associate I earn from qualifying purchases.

The function returns two objects: an array of integer indices and a dictionary of property arrays. The indices point into the original input, so you can retrieve the peak amplitudes with signal[peaks]. Properties appear when their corresponding conditions are evaluated; they are not all necessarily calculated for every call.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to use scipy.signal.find_peaks

Pass a one-dimensional signal and conditions that reflect what counts as a meaningful peak for your data:

from scipy.signal import find_peaks

peaks, properties = find_peaks(
    signal,
    prominence=minimum_prominence,
    distance=minimum_spacing_samples,
    width=minimum_width_samples,
)

peak_values = signal[peaks]

The names ending in _samples are reminders: distance and width are measured in samples, not seconds. If the sampling rate is fs samples per second, convert a time interval t to a sample count using t * fs, then choose an integer condition value as appropriate. The function does not take a sampling-rate argument. To get peak times, index your own time coordinate with peaks; with a uniform sampling interval, derive times from the sample indices and that interval.

Choose the right peak condition

height, threshold, and prominence express different ideas. Treating them as interchangeable is a common cause of confusing results.

Condition What it measures When it helps
height Peak amplitude in the original signal’s units. Use when an absolute amplitude cutoff has meaning, such as excluding peaks below a known level.
threshold Vertical difference between the peak and its immediate neighboring samples. Use to require local contrast. It is not a baseline-relative measure.
distance Minimum horizontal separation between retained peak indices, in samples. Use to enforce spacing. If peaks are too close, smaller peaks are removed first.
prominence Vertical distance from a peak down to its lowest surrounding contour line. Useful when a peak should stand out from its surroundings despite a changing baseline.
width Peak width in samples at a level determined by rel_height. Use to select peaks by breadth. State rel_height when interpreting or reporting widths; do not assume this is always full width at half maximum.
plateau_size Flat-top extent in samples. Use when the duration of a flat maximum matters. This condition was introduced in SciPy 1.2.0.

Except for distance, conditions can take lower and upper bounds. Several also accept arrays shaped like the signal, allowing position-dependent limits. For applicable properties, the open interval (None, None) requests property calculation without excluding peaks. SciPy evaluates conditions in this order: plateau_size, height, threshold, distance, prominence, and width.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand find_peaks prominence and wlen

Prominence describes how far a peak rises above its surrounding contour, rather than how high it is in absolute terms. For each peak, SciPy extends a horizontal line outward until it reaches the window boundary or the slope of a higher peak. It finds the minimum on each side; the higher of those two minima defines the contour line. The prominence is the vertical distance from that line to the peak. The SciPy 1.18.0 peak_prominences documentation describes this calculation.

wlen limits the region searched for prominence, and can also affect width calculations. A shorter window may reduce work on long or periodic signals, but it can prevent the search from reaching the contour that would be found over a wider region. The resulting prominence can therefore be smaller and more local. Choose wlen based on whether you want local or broader-context prominence, not solely as a speed setting.

Interpret example settings in context

SciPy’s manuals show ECG examples using height=0 and distance=150, and a separate ECG segment using prominence=1 and width=20. These are settings for the manual’s example data, not recommended defaults for other recordings. In particular, a sample spacing of 150 corresponds to different time intervals at different sampling rates. See the SciPy 1.15.3 find_peaks examples.

Prepare noisy or incomplete signals deliberately

  • Noise: Noise can shift the locations of local maxima. If you smooth or otherwise preprocess a signal, choose a method that preserves the feature you want to detect and document that processing. SciPy also points to alternatives such as find_peaks_cwt; neither preprocessing nor an alternative is automatically appropriate for every signal.
  • NaNs: NaNs can lead to unexpected prominence results. Remove them, replace them under a justified rule, or process valid segments separately before interpreting peaks. The handling choice can affect the result.
  • Flat peaks and spacing: distance constrains the returned peak indices. The edges of flat plateaus can still be closer than that spacing.
  • Boundary context: A peak near a signal boundary or a restricted wlen has less surrounding data available for contextual prominence calculations. Interpret the resulting value in light of that limited search region.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to consider another SciPy method

find_peaks fits one-dimensional sampled data when its neighboring-sample definition and optional filters match the task. SciPy also lists argrelmax, argrelextrema, find_peaks_cwt, peak_prominences, and peak_widths in its signal-processing function index. Consider the expected peak shape and width, noise level, boundary behavior, missing values, and whether you need local maxima, prominence, or wavelet-scale detection before switching methods; no single method is universally best.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Data AnalysisPythonSciPysignal processing

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.