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

Functions

 PitchTimeAmdf (x, iBlockLength, iHopLength, f_s)
 computes f0 via the lag of the amdf function
 

Function Documentation

◆ PitchTimeAmdf()

PitchTimeAmdf ( x,
iBlockLength,
iHopLength,
f_s )

computes f0 via the lag of the amdf 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 18 of file PitchTimeAmdf.py.

18def PitchTimeAmdf(x, iBlockLength, iHopLength, f_s):
19 def computeAmdf(x, eta_max):
20 K = x.shape[0]
21
22 if K <= 0:
23 return 0
24
25 afAmdf = np.ones(K)
26
27 for eta in range(0, np.min([K, eta_max + 1])):
28 afAmdf[eta] = np.sum(np.abs(x[np.arange(0, K - 1 - eta)] - x[np.arange(eta + 1, K)])) / K
29
30 return afAmdf
31
32
33 # initialize
34 f_max = 2000
35 f_min = 50
36
37 # block audio data
38 x_b, t = ToolBlockAudio(x, iBlockLength, iHopLength, f_s)
39 iNumOfBlocks = x_b.shape[0]
40
41 # allocate memory
42 f_0 = np.zeros(iNumOfBlocks)
43
44 eta_min = np.floor(f_s / f_max).astype(int)
45 eta_max = np.floor(f_s / f_min).astype(int)
46
47 for n, block in enumerate(x_b):
48
49 # calculate the amdf if non zero
50 if not block.sum():
51 continue
52 else:
53 afCorr = computeAmdf(block, eta_max)
54
55 # find the coefficients specified in eta
56 f_0[n] = np.argmin(afCorr[np.arange(eta_min + 1, afCorr.size)]) + 1
57
58 # convert to Hz
59 f_0[n] = f_s / (f_0[n] + eta_min + 1)
60
61 return f_0, t