Caution
You're reading the documentation for a development version. For the latest released version, please have a look at 0.11.0.
librosa.util.interp_broadcast
- librosa.util.interp_broadcast(*, x1, x1_pos, x2, x2_pos, interp_pos=None, op=<ufunc 'multiply'>, kind='linear', fill_value=0, axis=-2)[source]
Broadcast two arrays using interpolation
Interpolates two arrays along a given axis to a common grid, and performs a broadcast operation (eg.
np.multiply) to combine them. It is useful for retrieving the DFT / AC product [1] and the Fundamental Tempogram [2].[1]Peeters, G. “Spectral and Temporal Periodicity Representations of Rhythm for the Automatic Classification of Music Audio Signal.” In IEEE Transactions on Audio, Speech, and Language Processing, vol. 19, no. 5, pp. 1242–1252, July 2011.
[2]Cozens, James, and Simon Godsill. “Dynamic Time Signature Recognition, Tempo Inference, and Beat Tracking Through the Metrogram Transform.” In IEEE Open Journal of Signal Processing, pp. 1–9, 2023.
- Parameters:
- x1np.ndarray
An array with broadcast compatible dimensions (except along the axis of interpolation) with
x2.- x1_posnp.ndarray
Positioning data along the axis of interpolation for
x1.- x2np.ndarray
An array with broadcast compatible dimensions (except along the axis of interpolation) with
x1.- x2_posnp.ndarray
Positioning data along the axis of interpolation for
x2.- interp_posnp.ndarray
Positioning data for the interpolation grid. Default:
x1_pos.- opfunction [optional]
A broadcast operation performed on the two interpolated arrays. Default:
np.multiply.- kindstr
Interpolation type. See
scipy.interpolate.interp1d. Default:"linear"- fill_valuefloat
The value to fill when extrapolating beyond the observed range. Default:
0- axisint
The axis of interpolation. Default:
-2
- Returns:
- resultnp.ndarray or (np.ndarray, np.ndarray)
The result from combining both arrays after interpolation. If
opis set toNone, returns the interpolated arrays separately(y1, y2).
See also
Examples
>>> import numpy as np >>> >>> # two arrays of different lengths and sampling positions >>> x1 = np.array([1, 1, 1]) >>> x1_pos = np.array([0, 0.5, 1]) >>> x2 = np.array([5, 10]) >>> x2_pos = np.array([0, 1]) >>> >>> # interpolate to x1_pos and broadcast multiply (the defaults) >>> product = librosa.util.interp_broadcast( ... x1=x1, ... x1_pos=x1_pos, ... x2=x2, ... x2_pos=x2_pos, ... axis=0, ... ) >>> >>> product array([ 5. , 7.5, 10. ])