librosa.feature.inverse.pitch_to_stft#

librosa.feature.inverse.pitch_to_stft(P, *, sr=22050, n_fft=2048, power=2.0, n_pitches=None, fmin=None, intervals='equal', bins_per_octave=12, tuning=0.0, filter_window=None, norm=None, **kwargs)[source]#

Approximate STFT magnitude from a musical pitch spectrogram.

Parameters:
Pnp.ndarray [shape=(…, n_pitches, t), non-negative]

The pitch spectrogram as produced by feature.pitch_spectrogram

srnumber > 0 [scalar]

Sampling rate of the underlying signal.

n_fftint > 0 [scalar]

Length of the FFT frame of the resulting STFT; the output has 1 + n_fft // 2 frequency bins.

powerfloat > 0 [scalar]

Exponent for the magnitude spectrogram.

n_pitchesint > 0 [scalar, optional]

Number of pitch bands. If None, defaults to P.shape[-2].

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’.

intervalsstr or collection of float, default=’equal’

Interval system used to construct the pitch filterbank.

bins_per_octaveint > 0 [scalar], default=12

Number of bins per octave in the interval system.

tuningfloat, default=0.0

Tuning deviation from A440 in fractional bins.

filter_windowstr, callable, or None, default=None

Filter shape for each pitch band.

norm{None, ‘slaney’, or number}, default=None

Normalization applied to each filter row.

**kwargsadditional keyword arguments

Additional keyword arguments for librosa.filters.pitch_filterbank.

Returns:
Snp.ndarray [shape=(…, 1 + n_fft // 2, t), non-negative]

An approximate linear magnitude spectrogram.

Raises:
ParameterError

If n_pitches is provided and does not match P.shape[-2].

Examples

>>> y, sr = librosa.loadx("trumpet")
>>> S = librosa.util.abs2(librosa.stft(y))
>>> pitch_spec = librosa.feature.pitch_spectrogram(
...     S=S, sr=sr, n_pitches=84, fmin="C1"
... )
>>> S_inv = librosa.feature.inverse.pitch_to_stft(
...     pitch_spec, sr=sr, n_pitches=84, fmin="C1"
... )