scipy.signal. find_peaks (x, height=None, threshold=None, distance=None, prominence=None, width=None, wlen=None, rel_height=0.5, plateau_size=None)[source]
Find peaks inside a signal based on peak properties. This function takes a one-dimensional array and finds all local maxima by
simple comparison of neighbouring values. Optionally, a subset of these
peaks can be selected by specifying conditions for a peak’s properties. Parameters xsequence A signal with peaks. heightnumber or ndarray or sequence, optional Required height of peaks. Either a number, None , an array matchingx or a 2-element sequence of the former. The first element is
always interpreted as the minimal and the second, if supplied, as the
maximal required height. thresholdnumber or ndarray or sequence, optional Required threshold of peaks, the vertical distance to its neighbouring
samples. Either a number, None , an array matching x or a
2-element sequence of the former. The first element is always
interpreted as the minimal and the second, if supplied, as the maximal
required threshold. distancenumber, optional Required minimal horizontal distance (>= 1) in samples between
neighbouring peaks. Smaller peaks are removed first until the condition
is fulfilled for all remaining peaks. prominencenumber or ndarray or sequence, optional Required prominence of peaks. Either a number, None , an array
matching x or a 2-element sequence of the former. The first
element is always interpreted as the minimal and the second, if
supplied, as the maximal required prominence. widthnumber or ndarray or sequence, optional Required width of peaks in samples. Either a number, None , an array
matching x or a 2-element sequence of the former. The first
element is always interpreted as the minimal and the second, if
supplied, as the maximal required width. wlenint, optional Used for calculation of the peaks prominences, thus it is only used if
one of the arguments prominence or width is given. See argumentwlen in peak_prominences for a full description of its effects. rel_heightfloat, optional Used for calculation of the peaks width, thus it is only used if widthis given. See argument rel_height in peak_widths for a full
description of its effects. plateau_sizenumber or ndarray or sequence, optional Required size of the flat top of peaks in samples. Either a number,None , an array matching x or a 2-element sequence of the former.
The first element is always interpreted as the minimal and the second,
if supplied as the maximal required plateau size. New in version 1.2.0. Examples To demonstrate this function’s usage we use a signal x supplied with
SciPy (see scipy.misc.electrocardiogram ). Let’s find all peaks (local
maxima) in x whose amplitude lies above 0. >>> >>> import matplotlib.pyplot as plt>>> from scipy.misc import electrocardiogram>>> from scipy.signal import find_peaks>>> x = electrocardiogram()[2000:4000]>>> peaks, _ = find_peaks(x, height=0)>>> plt.plot(x)>>> plt.plot(peaks, x[peaks], "x")>>> plt.plot(np.zeros_like(x), "--", color="gray")>>> plt.show() 
|