26def computeMelSpectrogram(x, f_s, afWindow=None, bLogarithmic=True, iBlockLength=4096, iHopLength=2048, iNumMelBands=128, fMaxInHz=None):
32 x = ToolPreprocAudio(x)
36 afWindow = ToolComputeHann(iBlockLength)
38 assert(afWindow.shape[0] == iBlockLength),
"parameter error: invalid window dimension"
41 [X, f, t] = computeSpectrogram(x, f_s,
None, iBlockLength, iHopLength)
50 M = 20 * np.log10(M + 1e-12)
59 f_max = min(f_max, f_s / 2)
60 f_fft = np.linspace(0, f_s / 2, iFftLength // 2 + 1)
61 H = np.zeros((iNumFilters, f_fft.size))
64 mel_min = ToolFreq2Mel(f_min)
65 mel_max = ToolFreq2Mel(f_max)
66 f_mel = ToolMel2Freq(np.linspace(mel_min, mel_max, iNumFilters + 2))
68 f_l = f_mel[0:iNumFilters]
69 f_c = f_mel[1:iNumFilters + 1]
70 f_u = f_mel[2:iNumFilters + 2]
72 afFilterMax = 2 / (f_u - f_l)
75 for c
in range(iNumFilters):
76 H[c] = np.logical_and(f_fft > f_l[c], f_fft <= f_c[c]) * \
77 afFilterMax[c] * (f_fft-f_l[c]) / (f_c[c]-f_l[c]) + \
78 np.logical_and(f_fft > f_c[c], f_fft < f_u[c]) * \
79 afFilterMax[c] * (f_u[c]-f_fft) / (f_u[c]-f_c[c])