librosa.segment.recurrence_novelty#
- librosa.segment.recurrence_novelty(rec, *, n=33, window=None, var=0.5, norm=1, kernel=None, clip=True, exclude=False, mode='same', boundary='fill', fillvalue=0.0)[source]#
Compute Foote’s novelty curve from a recurrence or self-similarity matrix.
Slides a checkerboard kernel along the main diagonal of rec to detect structural transitions [1]. Homogeneous musical sections appear as high-similarity blocks along the diagonal of rec. When two contrasting sections meet, the kernel aligns with the block boundary, producing a local peak in the novelty curve.
- Parameters:
- recnp.ndarray [shape=(…, n_frames, n_frames)]
Self-similarity or recurrence matrix. Note: Sparse matrices are not supported.
- nint > 0, default=33
Length of the checkerboard kernel if kernel is not provided.
- window_WindowSpec or None, default=None
Window type for the checkerboard kernel. Defaults to
None(unwindowed). Seelibrosa.filters.checkerboard_kernelfor details.- varfloat > 0, default=0.5
Gaussian variance parameter for the checkerboard kernel when
window='gaussian'.- normbool, float, or None, default=1
Normalization for the checkerboard kernel.
- kernelnp.ndarray or tuple, optional
Pre-computed filter kernel. If provided, n, window, var, norm are ignored.
- clipbool, default=True
If True, half-wave rectifies the output (negative novelty scores clipped to 0).
- excludebool, default=False
If True and
mode='same', zeroes out the first and lastn // 2values to suppress boundary artifacts (as in libfmp [2]).- mode{‘same’, ‘valid’, ‘full’}, default=’same’
Convolution mode passed to
diagonal_convolve.- boundarystr, default=’fill’
Boundary padding mode passed to
diagonal_convolve.- fillvaluefloat, default=0.0
Fill value for boundary padding.
- Returns:
- noveltynp.ndarray [shape=(…, n_out)]
1D novelty curve.
Notes
This function caches at level 30.
References
Examples
Compute and plot Foote’s novelty curve on a short excerpt using a 17-frame boxcar checkerboard kernel:
>>> y, sr = librosa.loadx("nutcracker", duration=30) >>> hop_length = 512 >>> 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) >>> rec = librosa.segment.recurrence_matrix( ... chroma_stack, mode="affinity", self=True ... ) >>> nov = librosa.segment.recurrence_novelty(rec, n=17)
Compare unwindowed (boxcar) and Gaussian-tapered novelty curves:
>>> nov_gauss = librosa.segment.recurrence_novelty( ... rec, n=17, window="gaussian", var=0.5 ... )
Plot the recurrence matrix and both novelty curves with proportional heights:
>>> import matplotlib.pyplot as plt >>> times = librosa.times_like(nov, sr=sr, hop_length=hop_length) >>> fig, ax = plt.subplots( ... nrows=2, sharex=True, height_ratios=[3, 1], layout="compressed" ... ) >>> librosa.display.specshow( ... rec, x_axis="time", y_axis="time", sr=sr, hop_length=hop_length, ax=ax[0] ... ) >>> ax[0].set(title="Recurrence Matrix") >>> ax[0].label_outer() >>> ax[1].plot(times, nov, label="Boxcar (default)") >>> ax[1].plot(times, nov_gauss, label="Gaussian (var=0.5)", linestyle="--") >>> ax[1].set(title="Foote Novelty Curve", xlabel="Time (s)") >>> ax[1].legend()