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 array

A lag matrix, as produced by recurrence_to_lag

Deprecated since version 1.1.0: Support for scipy.sparse.spmatrix inputs is deprecated and will be removed in version 2.0.0. Use scipy.sparse arrays instead.

axisint

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

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

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

Raises:
ParameterShapeError

If lag does not have the correct shape

Examples

>>> y, sr = librosa.loadx("nutcracker")
>>> hop_length = 1024
>>> chroma = librosa.feature.chroma_cqt(y=y, sr=sr, hop_length=hop_length)
>>> chroma_stack = librosa.feature.stack_memory(chroma, n_steps=10, delay=3)
>>> recurrence = librosa.segment.recurrence_matrix(chroma_stack)
>>> 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
>>> fig, ax = plt.subplots(nrows=2, ncols=2, sharex=True)
>>> librosa.display.specshow(
...     lag_pad, x_axis="s", y_axis="lag", hop_length=hop_length, ax=ax[0, 0]
... )
>>> ax[0, 0].set(title="Lag (zero-padded)")
>>> ax[0, 0].label_outer()
>>> librosa.display.specshow(
...     lag_nopad, x_axis="s", y_axis="time", hop_length=hop_length, ax=ax[0, 1]
... )
>>> ax[0, 1].set(title="Lag (no padding)")
>>> ax[0, 1].label_outer()
>>> librosa.display.specshow(
...     rec_pad, x_axis="s", y_axis="time", hop_length=hop_length, ax=ax[1, 0]
... )
>>> ax[1, 0].set(title="Recurrence (with padding)")
>>> librosa.display.specshow(
...     rec_nopad, x_axis="s", y_axis="time", hop_length=hop_length, ax=ax[1, 1]
... )
>>> ax[1, 1].set(title="Recurrence (without padding)")
>>> ax[1, 1].label_outer()
../../_images/librosa-segment-lag_to_recurrence-1.png