Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.

librosa.segment.lag_to_recurrence

librosa.segment.lag_to_recurrence(lag, axis=- 1)[source]

Convert a lag matrix into a recurrence matrix.

Parameters
lagnp.ndarray or scipy.sparse.spmatrix

A lag matrix, as produced by recurrence_to_lag

axisint

The axis corresponding to the time dimension. The alternate axis will be interpreted in lag coordinates.

Returns
recnp.ndarray or scipy.sparse.spmatrix [shape=(n, n)]

A recurrence matrix in (time, time) coordinates For sparse matrices, format will match that of lag.

Raises
ParameterErrorif lag does not have the correct shape

Examples

>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> hop_length = 1024
>>> mfccs = librosa.feature.mfcc(y=y, sr=sr, hop_length=hop_length)
>>> 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',
...                          hop_length=hop_length)
>>> plt.title('Lag (zero-padded)')
>>> plt.subplot(2, 2, 2)
>>> librosa.display.specshow(lag_nopad, x_axis='time', y_axis='time',
...                          hop_length=hop_length)
>>> plt.title('Lag (no padding)')
>>> plt.subplot(2, 2, 3)
>>> librosa.display.specshow(rec_pad, x_axis='time', y_axis='time',
...                          hop_length=hop_length)
>>> plt.title('Recurrence (with padding)')
>>> plt.subplot(2, 2, 4)
>>> librosa.display.specshow(rec_nopad, x_axis='time', y_axis='time',
...                          hop_length=hop_length)
>>> plt.title('Recurrence (without padding)')
>>> plt.tight_layout()
>>> plt.show()
../_images/librosa-segment-lag_to_recurrence-1.png