librosa.core.ifgram¶
-
librosa.core.
ifgram
(y, sr=22050, n_fft=2048, hop_length=None, win_length=None, window=’hann’, norm=False, center=True, ref_power=1e-06, clip=True, dtype=<class ‘numpy.complex64’>, pad_mode=’reflect’)[source]¶ Compute the instantaneous frequency (as a proportion of the sampling rate) obtained as the time-derivative of the phase of the complex spectrum as described by [1].
Calculates regular STFT as a side effect.
[1] Abe, Toshihiko, Takao Kobayashi, and Satoshi Imai. “Harmonics tracking and pitch extraction based on instantaneous frequency.” International Conference on Acoustics, Speech, and Signal Processing, ICASSP-95., Vol. 1. IEEE, 1995. Parameters: - y : np.ndarray [shape=(n,)]
audio time series
- sr : number > 0 [scalar]
sampling rate of y
- n_fft : int > 0 [scalar]
FFT window size
- hop_length : int > 0 [scalar]
hop length, number samples between subsequent frames. If not supplied, defaults to win_length / 4.
- win_length : int > 0, <= n_fft
Window length. Defaults to n_fft. See
stft
for details.- window : string, tuple, number, function, or np.ndarray [shape=(n_fft,)]
- a window specification (string, tuple, number);
see
scipy.signal.get_window
- a window function, such as
scipy.signal.hanning
- a user-specified window vector of length n_fft
See
stft
for details.- a window specification (string, tuple, number);
see
- norm : bool
Normalize the STFT.
- center : boolean
- If True, the signal y is padded so that frame
- D[:, t] (and if_gram) is centered at y[t * hop_length].
- If False, then D[:, t] at y[t * hop_length]
- ref_power : float >= 0 or callable
Minimum power threshold for estimating instantaneous frequency. Any bin with np.abs(D[f, t])**2 < ref_power will receive the default frequency estimate.
If callable, the threshold is set to ref_power(np.abs(D)**2).
- clip : boolean
- If True, clip estimated frequencies to the range [0, 0.5 * sr].
- If False, estimated frequencies can be negative or exceed 0.5 * sr.
- dtype : numeric type
Complex numeric type for D. Default is 64-bit complex.
- mode : string
If center=True, the padding mode to use at the edges of the signal. By default, STFT uses reflection padding.
Returns: - if_gram : np.ndarray [shape=(1 + n_fft/2, t), dtype=real]
Instantaneous frequency spectrogram: if_gram[f, t] is the frequency at bin f, time t
- D : np.ndarray [shape=(1 + n_fft/2, t), dtype=complex]
Short-time Fourier transform
See also
stft
- Short-time Fourier Transform
Examples
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> frequencies, D = librosa.ifgram(y, sr=sr) >>> frequencies array([[ 0.000e+00, 0.000e+00, ..., 0.000e+00, 0.000e+00], [ 3.150e+01, 3.070e+01, ..., 1.077e+01, 1.077e+01], ..., [ 1.101e+04, 1.101e+04, ..., 1.101e+04, 1.101e+04], [ 1.102e+04, 1.102e+04, ..., 1.102e+04, 1.102e+04]])