pyACA: Documentation 0.3.1
Source Code for Audio Content Analysis
All Classes Namespaces Files Functions Variables Pages
Functions
pyACA.PitchTimeAcf Namespace Reference

Functions

 PitchTimeAcf (x, iBlockLength, iHopLength, f_s)
 computes f0 via the lag of the autocorrelation function
 

Function Documentation

◆ PitchTimeAcf()

PitchTimeAcf ( x,
iBlockLength,
iHopLength,
f_s )

computes f0 via the lag of the autocorrelation function

Parameters
xarray with floating point audio data (dimension samples x channels)
iBlockLengthinternal block length
iHopLengthinternal hop length
f_ssample rate of audio data
Returns
f_0: fundamental frequency (in Hz)
t: time stamp

Definition at line 17 of file PitchTimeAcf.py.

17def PitchTimeAcf(x, iBlockLength, iHopLength, f_s):
18
19 # initialize
20 f_max = 2000
21 fMinThresh = .35
22
23 # block audio data
24 x_b, t = ToolBlockAudio(x, iBlockLength, iHopLength, f_s)
25 iNumOfBlocks = x_b.shape[0]
26
27 # allocate memory
28 f_0 = np.zeros(iNumOfBlocks)
29
30 for n, block in enumerate(x_b):
31 eta_min = np.floor(f_s / f_max).astype(int)
32
33 # calculate the acf if non zero
34 if not block.sum():
35 continue
36 else:
37 afCorr = np.correlate(block, block, "full") / np.dot(block, block)
38
39 afCorr = afCorr[np.arange(iBlockLength, afCorr.size)]
40
41 # update eta_min to avoid main lobe
42 eta_tmp = np.argmax(afCorr < fMinThresh)
43 eta_min = np.max([eta_min, eta_tmp])
44
45 afDeltaCorr = np.diff(afCorr)
46 eta_tmp = np.argmax(afDeltaCorr > 0)
47 eta_min = np.max([eta_min, eta_tmp])
48
49 # find the coefficients specified in eta
50 f_0[n] = np.argmax(afCorr[np.arange(eta_min + 1, afCorr.size)]) + 1
51
52 # convert to Hz
53 f_0[n] = f_s / (f_0[n] + eta_min + 1)
54
55 return f_0, t