librosa.segment.timelag_filter¶
-
librosa.segment.
timelag_filter
(function, pad=True, index=0)[source]¶ Filtering in the time-lag domain.
This is primarily useful for adapting image filters to operate on
structure_feature
output.Using
timelag_filter
is equivalent to the following sequence of operations:>>> data_tl = librosa.segment.recurrence_to_lag(data) >>> data_filtered_tl = function(data_tl) >>> data_filtered = librosa.segment.lag_to_recurrence(data_filtered_tl)
Parameters: function : callable
The filtering function to wrap, e.g.,
scipy.ndimage.median_filter
pad : bool
Whether to zero-pad the structure feature matrix
index : int >= 0
If function accepts input data as a positional argument, it should be indexed by index
Returns: wrapped_function : callable
A new filter function which applies in time-lag space rather than time-time space.
See also
Examples
Apply a 5-bin median filter to the diagonal of a recurrence matrix
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> mfcc = librosa.feature.mfcc(y=y, sr=sr) >>> rec = librosa.segment.recurrence_matrix(mfcc, sym=True) >>> from scipy.ndimage import median_filter >>> diagonal_median = librosa.segment.timelag_filter(median_filter) >>> rec_filtered = diagonal_median(rec, size=(1, 5), mode='mirror')
>>> import matplotlib.pyplot as plt >>> plt.figure() >>> plt.subplot(1, 2, 1) >>> librosa.display.specshow(rec, x_axis='time', y_axis='time', ... aspect='equal') >>> plt.title('Raw recurrence matrix') >>> plt.subplot(1, 2, 2) >>> librosa.display.specshow(rec_filtered, x_axis='time', y_axis='time', ... aspect='equal') >>> plt.title('Filtered recurrence matrix') >>> plt.tight_layout()