librosa.filters.pitch_filterbank#
- librosa.filters.pitch_filterbank(*, sr=None, n_fft=None, freq_in=None, n_pitches=128, fmin=None, intervals='equal', bins_per_octave=12, tuning=0.0, window=None, norm=None, dtype=<class 'numpy.float32'>)[source]#
Create a musical pitch-anchored filterbank.
Produces a linear transformation matrix mapping input frequency bins to discrete musical pitch bands under specified intonation assumptions.
- Parameters:
- srnumber > 0 [scalar, optional]
Audio sampling rate. Required if
freq_inis not specified.- n_fftint > 0 [scalar, optional]
Length of the FFT frame. Required if
freq_inis not specified.- freq_innp.ndarray [shape=(n_in,)], optional
Coordinates of input frequency bins. If not provided, computed as
fft_frequencies(sr=sr, n_fft=n_fft).- n_pitchesint > 0 [scalar], default=128
Number of pitch bands to generate. Default 128 covers MIDI notes 0 to 127.
- fminfloat > 0, str, or None, optional
Minimum pitch center frequency (or note name in SPN format, e.g. ‘C1’). If None, defaults to MIDI 0 (~8.18 Hz) when
n_pitches=128, or ‘C1’ (~32.7 Hz).- intervalsstr or collection of float, default=’equal’
Tuning / interval system to use:
‘equal’: Equal temperament.
‘pythagorean’: Pythagorean intervals.
‘ji3’, ‘ji5’, ‘ji7’: 3-limit, 5-limit, or 7-limit Just Intonation.
Collection of floats in [1, 2): Custom interval set.
- bins_per_octaveint > 0 [scalar], default=12
Number of bins per octave in the interval system.
- tuningfloat [scalar], default=0.0
Tuning deviation from A440 in fractions of a bin.
- windowstr, callable, or None, default=None
Filter shape for each pitch band:
None (or ‘ones’, ‘boxcar’): Rectangular indicator window \([f(p - 0.5), f(p + 0.5))\). With
norm=None, this identically reproduces libfmp.pool_pitch energy pooling.‘triangle’: Triangular center-weighted filter.
‘hann’: Raised-cosine bell.
‘gaussian’: Gaussian bump.
- norm{None, ‘slaney’, or number}, default=None
Normalization applied to each filter row. Default None performs unnormalized energy summation.
- dtypenp.dtype, default=np.float32
Data type of the output basis matrix.
- Returns:
- filterbanknp.ndarray [shape=(n_pitches, n_in)]
Pitch filter matrix:
Y = filterbank.dot(X)
Notes
This function caches at level 10.
Examples
Construct a 128-pitch boxcar filterbank (libfmp pool_pitch equivalent):
>>> fb = librosa.filters.pitch_filterbank(sr=22050, n_fft=2048) >>> fb.shape (128, 1025)
Construct a Just Intonation pitch filterbank:
>>> fb_ji = librosa.filters.pitch_filterbank( ... sr=22050, n_fft=2048, intervals="ji5", fmin="C1", n_pitches=84 ... ) >>> fb_ji.shape (84, 1025)
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> img = librosa.display.specshow( ... fb, ... x_axis="linear", ... y_axis="pitch_note", ... intervals="ji5", ... fmin=librosa.note_to_hz("C1"), ... sr=22050, ... n_fft=2048, ... ax=ax, ... ) >>> ax.set(ylabel="Pitch filter", title="Pitch filter bank") >>> fig.colorbar(img, ax=ax)