Skip to content

Commit 3501e1e

Browse files
Document MFCC processing conventions
1 parent c0c8640 commit 3501e1e

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

Source/TransformFunctions/arm_mfcc_f16.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,41 @@
5050
MFCC Transform
5151
5252
There are separate functions for floating-point, Q15, and Q31 data types.
53+
54+
@par Processing convention
55+
Each call processes one frame whose length is the configured FFT length. The
56+
function applies the configured window, computes the FFT magnitude, applies
57+
the configured Mel filter bank, takes the natural logarithm after adding a
58+
data-type-specific positive floor, and multiplies the result by the configured
59+
DCT matrix.
60+
61+
The Mel filters operate on the magnitude spectrum, not the squared magnitude
62+
(power spectrum). When comparing with an API that exposes a power exponent,
63+
use <code>power=1.0</code>.
64+
65+
The window, Mel filter bank, and DCT matrix are supplied during instance
66+
initialization, so the MFCC functions do not impose a particular window,
67+
Mel-scale normalization, DCT type, or DCT normalization. Comparisons with
68+
another MFCC implementation must use the same coefficient arrays.
69+
70+
The <code>cmsisdsp.mfcc</code> Python helper generates triangular filters on
71+
the HTK Mel scale
72+
73+
\f[
74+
m(f) = 1127 \ln\left(1 + \frac{f}{700}\right)
75+
\f]
76+
77+
without area normalization. Its DCT helper generates a type-II matrix. For
78+
<code>M</code> Mel filters, its entries are
79+
80+
\f[
81+
D_{k,n} = \sqrt{\frac{2}{M}}
82+
\cos\left(\frac{\pi k(n + 1/2)}{M}\right).
83+
\f]
84+
85+
The factor \f$\sqrt{2/M}\f$ is applied to every row, including
86+
<code>k=0</code>. This differs from an orthonormal DCT-II, whose first row uses
87+
\f$\sqrt{1/M}\f$.
5388
*/
5489

5590

cmsisdsp/mfcc.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
def frequencyToMelSpace(freq):
55
"""
6-
Convert a frequency in Hz to Mel space value
6+
Convert a frequency in Hz to an HTK Mel-space value.
7+
8+
The conversion is ``1127 * log(1 + freq / 700)``.
79
810
:param freq: Frequency in Hz.
911
:type freq: float
@@ -27,7 +29,11 @@ def melSpaceToFrequency(mels):
2729

2830
def melFilterMatrix(dtype,fmin, fmax, numOfMelFilters,fs,FFTSize):
2931
"""
30-
Sparse matrix in a specific format and encoding the filters in Mel space
32+
Generate a sparse matrix encoding triangular filters in Mel space.
33+
34+
Filter centers are equally spaced on the HTK Mel scale. The triangular
35+
weights are evaluated at the FFT bin center frequencies and are not area
36+
normalized.
3137
3238
:param dtype: The datatype to use for the matrix coefficients.
3339
:type dtype: int
@@ -91,7 +97,12 @@ def melFilterMatrix(dtype,fmin, fmax, numOfMelFilters,fs,FFTSize):
9197

9298
def dctMatrix(dtype,numOfDctOutputs, numOfMelFilters):
9399
"""
94-
Dct matrix in a specific format
100+
Generate the type-II DCT matrix used by the MFCC helper.
101+
102+
For ``M = numOfMelFilters``, element ``(k, n)`` is
103+
``sqrt(2 / M) * cos(pi * k * (n + 0.5) / M)``. The ``sqrt(2 / M)``
104+
factor is applied to every row, including ``k = 0``. This differs from an
105+
orthonormal DCT-II, whose first row is scaled by ``sqrt(1 / M)``.
95106
96107
:param dtype: The datatype to use for the matrix coefficients.
97108
:type dtype: int

0 commit comments

Comments
 (0)