← Back to the chapter · Previous detail · Next detail →

Technical detail · Audio Feature Extraction for IoT

Normalized spectrum and mel filter bank

For each windowed frame, compute an NN-point discrete Fourier transform

Xi[k]=∑n=0N−1xi[n]e−j2πkn/N.X_i[k]=\sum_{n=0}^{N-1}x_i[n]e^{-j2\pi kn/N}.

One common normalized power-spectrum convention is

Pi[k]=∣Xi[k]∣2N.P_i[k]=\frac{|X_i[k]|^2}{N}.

Libraries also use 1/N21/N^2, one-sided energy doubling, or window-energy normalization. Those conventions change feature magnitudes even when the waveform is identical, so record the FFT length, one- or two-sided spectrum, and normalization rule with the model.

The mel mapping compresses high physical frequencies:

m(f)=2595log⁡10(1+f700),f(m)=700(10m/2595−1).m(f)=2595\log_{10}\left(1+\frac{f}{700}\right), \qquad f(m)=700\left(10^{m/2595}-1\right).

For example, 1,000 Hz maps to about 1,000 mel, while 8,000 Hz maps to about 2,835 mel. Equal spacing in mel therefore puts filter centers close together at low frequency and farther apart in hertz at high frequency.

Build MM triangular filters step by step:

  1. Choose fminf_{min} and fmax≤fs/2f_{max}\leq f_s/2, map both to mel, and place M+2M+2 equally spaced points between them.
  2. Convert those points back to hertz and then to FFT-bin locations, for example bm=⌊(N+1)fm/fs⌋b_m=\left\lfloor(N+1)f_m/f_s\right\rfloor.
  3. For filter mm, rise linearly from zero at bm−1b_{m-1} to one at bmb_m, then fall to zero at bm+1b_{m+1}.
  4. Sum the power under each triangle:
Ei,m=∑kPi[k]Hm[k].E_{i,m}=\sum_k P_i[k]H_m[k].
  1. Apply log⁡(Ei,m+ϵ)\log(E_{i,m}+\epsilon) to turn multiplicative spectral changes into additive differences and prevent a zero-energy logarithm.

← Back to the chapter · Previous detail · Next detail →