gastropy.cycle_durations#
- gastropy.cycle_durations(phase, times)[source]#
Detect complete cycles from phase and return their durations.
Locates crossings at each 2pi increment of the unwrapped phase using linear interpolation to estimate boundary times. This is more robust than simple zero-crossing detection.
- Parameters:
phase (array_like) – Instantaneous phase in radians (from
instantaneous_phase).times (array_like) – Time values corresponding to each phase sample (in seconds).
- Returns:
durations – Duration of each detected cycle in seconds. Empty array if fewer than 2 cycle boundaries are found.
- Return type:
np.ndarray
Examples
>>> import numpy as np >>> from gastropy.signal import instantaneous_phase, cycle_durations >>> sfreq = 10.0 >>> t = np.arange(0, 300, 1 / sfreq) >>> sig = np.sin(2 * np.pi * 0.05 * t) # 20s cycles >>> phase, _ = instantaneous_phase(sig) >>> durs = cycle_durations(phase, t)