// If we don"t have a spectrogram, build one
if S is None:
// By default, use a magnitude spectrogram
S = np.abs(librosa.stft(y, n_fft=n_fft, hop_length=hop_length))
else:
// Infer n_fft from spectrogram shape
n_fft = (S.shape[0] - 1) * 2
// Compute the center frequencies of each bin
if freq is None:
freq = librosa.core.fft_frequencies(sr=sr, n_fft=n_fft)
if freq.ndim == 1:
coefficients = np.polyfit(freq, S, order)
else:
coefficients = np.concatenate([[np.polyfit(freq_t, S_t, order)]
for (freq_t, S_t) in zip(freq.T, S.T)],
axis=0).T
return coefficients