bycycle.features.compute_shape_features¶
- bycycle.features.compute_shape_features(sig, fs, f_range, center_extrema='peak', find_extrema_kwargs=None, n_cycles=3)[source]¶
Compute shape features for each cycle.
- Parameters:
- sig1d array
Time series.
- fsfloat
Sampling rate, in Hz.
- f_rangetuple of (float, float)
Frequency range for narrowband signal of interest (Hz).
- center_extrema{‘peak’, ‘trough’}
The center extrema in the cycle.
‘peak’ : cycles are defined trough-to-trough
‘trough’ : cycles are defined peak-to-peak
- find_extrema_kwargsdict, optional, default: None
Keyword arguments for function to find peaks and troughs (
find_extrema()
) to change filter parameters or boundary. By default, the filter length is set to three cycles of the low cutoff frequency (f_range[0]
).- n_cyclesint, optional, default: 3
Length of filter, in number of cycles, at the lower cutoff frequency.
- Returns:
- df_shape_featurespandas.DataFrame
Dataframe containing cycle shape features. Each row is one cycle. Columns:
period
: period of the cycletime_decay
: time between peak and next troughtime_rise
: time between peak and previous troughtime_peak
: time between rise and decay zero-crossestime_trough
: duration of previous trough estimated by zero-crossingsvolt_decay
: voltage change between peak and next troughvolt_rise
: voltage change between peak and previous troughvolt_amp
: average of rise and decay voltagevolt_peak
: voltage at the peakvolt_trough
: voltage at the last troughtime_rdsym
: fraction of cycle in the rise periodtime_ptsym
: fraction of cycle in the peak periodband_amp
: average analytic amplitude of the oscillationsample_peak
: sample at which the peak occurssample_zerox_decay
: sample of the decaying zero-crossingsample_zerox_rise
: sample of the rising zero-crossingsample_last_trough
: sample of the last troughsample_next_trough
: sample of the next trough
Notes
Peak vs trough centering:
By default, the first extrema analyzed will be a peak, and the final one a trough.
In order to switch the preference, the signal is simply inverted and columns are renamed.
Columns are slightly different dependent on
center_extrema
being ‘peak’ or ‘trough’.
Examples
Compute shape features:
>>> from neurodsp.sim import sim_bursty_oscillation >>> fs = 500 >>> sig = sim_bursty_oscillation(10, fs, freq=10) >>> df_shapes = compute_shape_features(sig, fs, f_range=(8, 12))