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

Functions

 ToolGammatoneFb (x, f_s, iNumBands=20, f_low=100)
 helper function: splits the audio signal into multiple bands via a Gammatone filterbank see function from Slaneys Auditory Toolbox (Matlab)
 
 getMidFrequencies (f_low, f_hi, iNumBands, fEarQ, fBW)
 
 getCoeffs (f_c, B, T)
 

Function Documentation

◆ getCoeffs()

getCoeffs ( f_c,
B,
T )

Definition at line 53 of file ToolGammatoneFb.py.

53def getCoeffs(f_c, B, T):
54
55 fCos = np.cos(2 * f_c * np.pi * T)
56 fSin = np.sin(2 * f_c * np.pi * T)
57 fExp = np.exp(B * T)
58 fSqrtA = 2 * np.sqrt(3 + 2**(3 / 2))
59 fSqrtS = 2 * np.sqrt(3 - 2**(3 / 2))
60
61 A0 = T
62 A2 = 0
63 B0 = 1
64 B1 = -2 * fCos / fExp
65 B2 = np.exp(-2 * B * T)
66
67 A11 = -(2 * T * fCos / fExp + fSqrtA * T * fSin / fExp) / 2
68 A12 = -(2 * T * fCos / fExp - fSqrtA * T * fSin / fExp) / 2
69 A13 = -(2 * T * fCos / fExp + fSqrtS * T * fSin / fExp) / 2
70 A14 = -(2 * T * fCos / fExp - fSqrtS * T * fSin / fExp) / 2
71
72 fSqrtA = np.sqrt(3 + 2**(3 / 2))
73 fSqrtS = np.sqrt(3 - 2**(3 / 2))
74 fArg = (f_c * np.pi * T) * 1j
75
76 fExp1 = 2 * np.exp(4 * fArg)
77 fExp2 = 2 * np.exp(-(B * T) + 2 * fArg)
78
79 afGain = np.abs((-fExp1 * T + fExp2 * T * (fCos - fSqrtS * fSin)) *
80 (-fExp1 * T + fExp2 * T * (fCos + fSqrtS * fSin)) *
81 (-fExp1 * T + fExp2 * T * (fCos - fSqrtA * fSin)) *
82 (-fExp1 * T + fExp2 * T * (fCos + fSqrtA * fSin)) /
83 (-2 / np.exp(2 * B * T) - fExp1 + (2 + fExp1) / fExp)**4)
84
85 # this is Slaney's compact format - now resort into 3D Matrices
86 # fcoefs = [A0*ones(length(f_c),1) A11 A12 A13 A14 A2*ones(length(f_c),1) B0*ones(length(f_c),1) B1 B2 afGain];
87
88 afCoeffB = np.zeros([4, 3, B.size])
89 afCoeffA = np.zeros([4, 3, B.size])
90
91 for k in range(0, B.size):
92 afCoeffB[0, :, k] = [A0, A11[k], A2] / afGain[k]
93 afCoeffA[0, :, k] = [B0, B1[k], B2[k]]
94
95 afCoeffB[1, :, k] = [A0, A12[k], A2]
96 afCoeffA[1, :, k] = [B0, B1[k], B2[k]]
97
98 afCoeffB[2, :, k] = [A0, A13[k], A2]
99 afCoeffA[2, :, k] = [B0, B1[k], B2[k]]
100
101 afCoeffB[3, :, k] = [A0, A14[k], A2]
102 afCoeffA[3, :, k] = [B0, B1[k], B2[k]]
103
104 return afCoeffB, afCoeffA
Here is the caller graph for this function:

◆ getMidFrequencies()

getMidFrequencies ( f_low,
f_hi,
iNumBands,
fEarQ,
fBW )

Definition at line 43 of file ToolGammatoneFb.py.

43def getMidFrequencies(f_low, f_hi, iNumBands, fEarQ, fBW):
44
45 freq = np.log((f_low + fEarQ * fBW) / (f_hi + fEarQ * fBW)) / iNumBands
46 f_c = np.exp(np.arange(1, iNumBands + 1) * freq)
47 f_c = -(fEarQ * fBW) + f_c * (f_hi + fEarQ * fBW)
48
49 return f_c
50
51
52# see function MakeERBFilters.m from Slaneys Auditory Toolbox
Here is the caller graph for this function:

◆ ToolGammatoneFb()

ToolGammatoneFb ( x,
f_s,
iNumBands = 20,
f_low = 100 )

helper function: splits the audio signal into multiple bands via a Gammatone filterbank see function from Slaneys Auditory Toolbox (Matlab)

Parameters
xarray with floating point audio data (dimension samples x channels)
f_ssample rate of audio data
iNumBandsnumber of filter bands (default: 20)
f_lowminimum frequency (default: 100Hz)
Returns
X: multi-band signal

Definition at line 16 of file ToolGammatoneFb.py.

16def ToolGammatoneFb(x, f_s, iNumBands=20, f_low=100):
17
18 # initialization
19 fEarQ = 9.26449
20 fBW = 24.7
21 iOrder = 1
22 T = 1 / f_s
23
24 # allocate output memory
25 X = np.zeros([iNumBands, x.shape[0]])
26
27 # compute the mid frequencies
28 f_c = getMidFrequencies(f_low, f_s / 2, iNumBands, fEarQ, fBW)
29
30 # compute the coefficients
31 [afCoeffB, afCoeffA] = getCoeffs(f_c, 1.019 * 2 * np.pi * (((f_c / fEarQ)**iOrder + fBW**iOrder)**(1 / iOrder)), T)
32
33 # do the (cascaded) filter process
34 for k in range(0, iNumBands):
35 X[k, :] = x
36 for j in range(0, 4):
37 X[k, :] = lfilter(afCoeffB[j, :, k], afCoeffA[j, :, k], X[k, :])
38
39 return X
40
41
42# see function ERBSpace.m from Slaneys Auditory Toolbox
Here is the call graph for this function: