librosa.segment.lag_to_recurrence¶
- librosa.segment.lag_to_recurrence(lag, axis=-1)[source]¶
Convert a lag matrix into a recurrence matrix.
Parameters: lag : np.ndarray [shape=(2*n, n) or (n, n)]
A lag matrix, as produced by recurrence_to_lag
axis : int
The axis along which to apply the recurrence-to-lag conversion
Returns: rec : np.ndarray [shape=(n, n)]
A recurrence matrix in (time, time) coordinates
Raises: ParameterError : if lag does not have the correct shape
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) >>> rec_pad = librosa.segment.lag_to_recurrence(lag_pad) >>> rec_nopad = librosa.segment.lag_to_recurrence(lag_nopad)
>>> import matplotlib.pyplot as plt >>> plt.figure(figsize=(8, 4)) >>> plt.subplot(2, 2, 1) >>> librosa.display.specshow(lag_pad, x_axis='time', y_axis='lag') >>> plt.title('Lag (zero-padded)') >>> plt.subplot(2, 2, 2) >>> librosa.display.specshow(lag_nopad, x_axis='time', y_axis='time') >>> plt.title('Lag (no padding)') >>> plt.subplot(2, 2, 3) >>> librosa.display.specshow(rec_pad, x_axis='time', y_axis='time') >>> plt.title('Recurrence (with padding)') >>> plt.subplot(2, 2, 4) >>> librosa.display.specshow(rec_nopad, x_axis='time', y_axis='time') >>> plt.title('Recurrence (without padding)') >>> plt.tight_layout()