maad.features.temporal_quantile

maad.features.temporal_quantile(s, fs, q=[0.05, 0.25, 0.5, 0.75, 0.95], nperseg=1024, roi=None, mode='spectrum', env_mode='fast', as_pandas=False, amp=False, **kwargs)[source]

Compute the q-th temporal quantile of the waveform or spectrum. If a region of interest with time and spectral limits is provided, the q-th temporal quantile is computed on the selection.

Parameters:
s1D array

Input audio signal

fsfloat

Sampling frequency of audio signal

qarray or float, optional

Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive. The defaul is [0.05, 0.25, 0.5, 0.75, 0.95].

npersegint, optional

Length of segment to compute the FFT when mode is spectrum. The default is 1024. Size of each frame to compute the envelope. The largest, the highest is the approximation. The default is 5000.

roipandas.Series, optional

Region of interest where peak frequency 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 in the espectrum.

  • ‘envelope’ : The quantile is calculated in the 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: bool

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

amp: bool, default is False

Return the quantiles with its amplitude.

Returns:
quantiles: pandas Series/DataFrame or Numpy array

Temporal quantiles of waveform and its amplitude (optional).

Examples

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

Compute the q-th temporal quantile in the spectrum

>>> qt = features.temporal_quantile(s, fs, [0.05, 0.25, 0.5, 0.75, 0.95], as_pandas=True)
>>> print(qt)
0.05     1.219048
0.25     5.712109
0.50    11.818957
0.75    16.555828
0.95    17.751655
dtype: float64

Compute the q-th temporal quantile in the waveform, using the envelope

>>> qt = features.temporal_quantile(s, fs, [0.05, 0.25, 0.5, 0.75, 0.95], mode="envelope", as_pandas=True)
>>> print(qt)
0.05     1.208300
0.25     5.716188
0.50    11.804161
0.75    15.731135
0.95    17.752714
dtype: float64