librosa.segment.recurrence_to_lag¶
-
librosa.segment.
recurrence_to_lag
(rec, pad=True, axis=-1)[source]¶ Convert a recurrence matrix into a lag matrix.
lag[i, j] == rec[i+j, j]Parameters: rec : np.ndarray, [shape=(n, n)]
A (binary) recurrence matrix, as returned by
recurrence_matrix
pad : bool
If False, lag matrix is square, which is equivalent to assuming that the signal repeats itself indefinitely.
If True, lag is padded with n zeros, which eliminates the assumption of repetition.
axis : int
The axis along which to apply the recurrence-to-lag conversion
Returns: lag : np.ndarray [shape=(2*n, n) or (n, n)]
The recurrence matrix in (lag, time) coordinates
Raises: ParameterError : if rec is non-square
See also
Examples
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> mfccs = librosa.feature.mfcc(y=y, sr=sr) >>> recurrence = librosa.segment.recurrence_matrix(mfccs) >>> lag_pad = librosa.segment.recurrence_to_lag(recurrence, pad=True) >>> lag_nopad = librosa.segment.recurrence_to_lag(recurrence, pad=False)
>>> import matplotlib.pyplot as plt >>> plt.figure(figsize=(8, 4)) >>> plt.subplot(1, 2, 1) >>> librosa.display.specshow(lag_pad, x_axis='time', y_axis='lag') >>> plt.title('Lag (zero-padded)') >>> plt.subplot(1, 2, 2) >>> librosa.display.specshow(lag_nopad, x_axis='time', y_axis='time') >>> plt.title('Lag (no padding)') >>> plt.tight_layout()