bycycle.cyclepoints.find_extrema¶
- bycycle.cyclepoints.find_extrema(sig, fs, f_range, boundary=0, first_extrema='peak', filter_kwargs=None, pass_type='bandpass', pad=True)[source]¶
Identify peaks and troughs in a time series.
- Parameters:
- sig1d array
Time series.
- fsfloat
Sampling rate, in Hz.
- f_rangetuple of (float, float)
Frequency range, in Hz, to narrowband filter the signal, used to find zero-crossings.
- boundaryint, optional, default: 0
Number of samples from edge of the signal to ignore.
- first_extrema: {‘peak’, ‘trough’, None}
If ‘peak’, then force the output to begin with a peak and end in a trough. If ‘trough’, then force the output to begin with a trough and end in peak. If None, force nothing.
- filter_kwargsdict, optional, default: None
Keyword arguments to
filter_signal()
, such as ‘n_cycles’ or ‘n_seconds’ to control filter length.- pass_typestr, optional, default: ‘bandpass’
Which kind of filter pass_type is consistent with the frequency definition provided.
- padbool, optional, default: True
Whether to pad
sig
with zeros to prevent missed cyclepoints at the edges.
- Returns:
- peaks1d array
Indices at which oscillatory peaks occur in the input
sig
.- troughs1d array
Indices at which oscillatory troughs occur in the input
sig
.
Notes
This function assures that there are the same number of peaks and troughs if the first extrema is forced to be either peak or trough.
Examples
Find the locations of peaks and burst in a signal:
>>> from neurodsp.sim import sim_bursty_oscillation >>> fs = 500 >>> sig = sim_bursty_oscillation(10, fs, freq=10) >>> peaks, troughs = find_extrema(sig, fs, f_range=(8, 12))