maad.features.temporal_duration

maad.features.temporal_duration(s, fs, nperseg=1024, roi=None, mode='spectrum', env_mode='fast', as_pandas=False, **kwargs)[source]

Compute the temporal duration of the waveform. If a region of interest with time and spectral limits is provided, the temporal duration is computed on the selection.

Parameters:
s1D array

Input audio signal

fsfloat

Sampling frequency of audio signal

npersegint, optional

Length of segment to compute the FFT. The default is 1024.

roipandas.Series, optional

Region of interest where temporal duration will be computed. Series must have a valid input format with index: min_t, min_f, max_t, max_f. The default is None.

modestr, optional, default is ‘spectrum’
  • ‘spectrum’ : The quantile is calculated using the spectrum.

  • ‘amplitude’ : The quantile is calculated using the enveloppe sound wave.

env_modestr, optional, default is fast
  • fastThe sound is first divided into frames (2d) using the

    function wave2timeframes(s), then the max of each frame gives a good approximation of the envelope.

  • Hilbertestimation of the envelope from the Hilbert transform.

    The method is slow

as_pandas_series: bool

Return data as a pandas.Series. This is usefull when computing multiple features over a signal. Default is False.

Returns:
duration: pandas Series/DataFrame or Numpy array

Temporal duration of signal using energy quantiles.

Examples

>>> from maad import features, sound
>>> s, fs = sound.load('../data/spinetail.wav')

Compute the temporal duration of the time energy

>>> duration, duration_90 = features.temporal_duration(s, fs)
>>> print("Duration 50%: {:.4f} / Duration 90%: {:.4f}".format(duration, duration_90))
Duration 50%: 10.8437 / Duration 90%: 16.5326