pyACA: Documentation 0.3.1
Source Code for Audio Content Analysis
Loading...
Searching...
No Matches
Functions
pyACA.PitchSpectralAcf Namespace Reference

Functions

 PitchSpectralAcf (X, f_s)
 computes f0 via the maximum of the spectral autocorrelation function
 

Function Documentation

◆ PitchSpectralAcf()

PitchSpectralAcf ( X,
f_s )

computes f0 via the maximum of the spectral autocorrelation function

Parameters
Xspectrogram (dimension FFTLength X Observations)
f_ssample rate of audio data
Returns
f_0: fundamental frequency (in Hz)

Definition at line 13 of file PitchSpectralAcf.py.

13def PitchSpectralAcf(X, f_s):
14
15 # initialize
16 f_min = 300
17 f_0 = np.zeros(X.shape[1])
18
19 # use spectral symmetry for robustness
20 X[0, :] = np.max(X)
21 X = np.concatenate((np.flipud(X[1:,:]), X[:-1,:]), axis=0)
22
23 # compute the ACF
24 for n in range(0, X.shape[1]):
25
26 if X[:, n].sum() < 1e-20:
27 continue
28
29 eta_min = int(round(f_min / f_s * (X.shape[0] - 2))) - 1
30
31 afCorr = np.correlate(X[:, n], X[:, n], "full") / np.dot(X[:, n], X[:, n])
32 afCorr = afCorr[np.arange(X.shape[0], afCorr.size)]
33
34 # find the highest local maximum
35 iPeaks = find_peaks(afCorr, height=0)
36 if iPeaks[0].size:
37 eta_min = np.max([eta_min, iPeaks[0][0] - 1])
38 f_0[n] = np.argmax(afCorr[np.arange(eta_min, afCorr.size)]) + 1
39
40 # find max index and convert to Hz (note: X has double length)
41 f_0[n] = (f_0[n] + eta_min) / (X.shape[0] - 2) * f_s
42
43 return f_0