Caution
You're reading the documentation for a development version. For the latest released version, please have a look at 0.11.0.
librosa.effects.percussive
- librosa.effects.percussive(y, *, kernel_size=31, power=2.0, mask=False, margin=1.0, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')[source]
Extract percussive elements from an audio time-series.
- Parameters:
- ynp.ndarray [shape=(…, n)]
audio time series. Multi-channel is supported.
- kernel_sizeint or tuple (kernel_harmonic, kernel_percussive)
Kernel size(s) for the median filters.
If scalar, the same size is used for both harmonic and percussive.
If tuple, the first value specifies the width of the harmonic filter, and the second value specifies the width of the percussive filter.
- powerfloat > 0 [scalar]
Exponent for the Wiener filter when constructing soft mask matrices.
- maskbool
Return the masking matrices instead of components.
- marginfloat or tuple (margin_harmonic, margin_percussive)
Margin size(s) for the masks.
If scalar, the same size is used for both harmonic and percussive.
If tuple, the first value specifies the margin of the harmonic mask, and the second value specifies the margin of the percussive mask.
- n_fftint > 0 [scalar]
Length of the windowed signal after padding with zeros. The number of rows in the STFT matrix is
(1 + n_fft/2).- hop_lengthint or None
Number of audio samples between adjacent STFT columns. If unspecified, defaults to
win_length // 4.- win_lengthint or None
Each frame of audio is windowed by
windowof lengthwin_lengthand then padded with zeros to matchn_fft. If unspecified, defaults towin_length = n_fft.- windowstr, tuple, number, function, or np.ndarray [shape=(n_fft,)]
Window specification. See
scipy.signal.get_windowfor supported values.- centerbool
If
True, the signal is padded so that frametis centered aty[t * hop_length].- pad_modestr
Padding mode used when
center=True. Seenumpy.padfor available modes.
- Returns:
- y_percussivenp.ndarray [shape=(…, n)]
audio time series of just the percussive portion
See also
hpssSeparate harmonic and percussive components
harmonicExtract only the harmonic component
librosa.decompose.hpssHPSS for spectrograms
Examples
>>> # Extract percussive component >>> y, sr = librosa.loadx('choice') >>> y_percussive = librosa.effects.percussive(y)
>>> # Use a margin > 1.0 for greater percussive separation >>> y_percussive = librosa.effects.percussive(y, margin=3.0)