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

Functions

 PitchTimeAuditory (x, iBlockLength, iHopLength, f_s)
 computes f0 via the "auditory" approach
 

Function Documentation

◆ PitchTimeAuditory()

PitchTimeAuditory ( x,
iBlockLength,
iHopLength,
f_s )

computes f0 via the "auditory" approach

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 20 of file PitchTimeAuditory.py.

20def PitchTimeAuditory(x, iBlockLength, iHopLength, f_s):
21
22 # initialize
23 iNumOfBlocks = math.ceil(x.size / iHopLength)
24 f_0 = np.zeros(iNumOfBlocks)
25 f_max = 2000
26 iNumBands = 20
27 fLengthLpInS = 0.001
28
29 iLengthLp = math.ceil(fLengthLpInS * f_s)
30
31 # compute time stamps
32 t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s
33
34 # apply filterbank
35 X = ToolGammatoneFb(x, f_s, iNumBands)
36
37 # half wave rectification
38 X[X < 0] = 0
39
40 # smooth the results with a moving average filter
41 b = np.ones(iLengthLp) / iLengthLp
42 X = filtfilt(b, 1, X)
43
44 for n in range(0, iNumOfBlocks):
45
46 eta_min = int(round(f_s / f_max))
47 afSumCorr = np.zeros(iBlockLength - 1)
48 x_tmp = np.zeros(iBlockLength)
49
50 i_start = n * iHopLength
51 i_stop = np.min([x.size - 1, i_start + iBlockLength - 1])
52
53 # compute ACF per band and summarize
54 for k in range(0, iNumBands):
55 # get current block
56 if X[k, np.arange(i_start, i_stop + 1)].sum() < 1e-20:
57 continue
58 else:
59 x_tmp[np.arange(0, i_stop - i_start + 1)] = X[k, np.arange(i_start, i_stop + 1)]
60
61 afCorr = np.correlate(x_tmp, x_tmp, "full") / np.dot(x_tmp, x_tmp)
62
63 # aggregate bands with simple sum before peak picking
64 afSumCorr += afCorr[np.arange(iBlockLength, afCorr.size)]
65
66 if afSumCorr.sum() < 1e-20:
67 continue
68
69 # find the highest local maximum
70 iPeaks = find_peaks(afSumCorr, height=0)
71 if iPeaks[0].size:
72 eta_min = np.max([eta_min, iPeaks[0][0] - 1])
73 f_0[n] = np.argmax(afSumCorr[np.arange(eta_min + 1, afSumCorr.size)]) + 1
74
75 # convert to Hz
76 f_0[n] = f_s / (f_0[n] + eta_min + 1)
77
78 return f_0, t