joelle-o-world / mfcc

Calculate MFCC (Mel-frequency Cepstral Coefficients) from mic input in the browser. (TypeScript)
1 stars 0 forks source link

Does dct npm package match dct implementation used in python version? #11

Open joelle-o-world opened 4 years ago

joelle-o-world commented 4 years ago

Discrete cosine transform package used: https://www.npmjs.com/package/dct

joelle-o-world commented 4 years ago

"...this implementation uses the DCT-II with a scaling factor of 2."

joelle-o-world commented 4 years ago

feat = dct(feat, type=2, axis=1, norm='ortho')[:,:numcep]

from python lib

joelle-o-world commented 4 years ago

DCT-II ✅

joelle-o-world commented 4 years ago

Type II

There are several definitions of the DCT-II; we use the following (for norm=None):

          N-1
y[k] = 2* sum x[n]*cos(pi*k*(2n+1)/(2*N)), 0 <= k < N.
          n=0

If norm='ortho', y[k] is multiplied by a scaling factor f:

f = sqrt(1/(4*N)) if k = 0,
f = sqrt(1/(2*N)) otherwise.

Which makes the corresponding matrix of coefficients orthonormal (OO' = Id).

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.fftpack.dct.html

joelle-o-world commented 4 years ago

Looks like there may be some deviation between the two libraries in terms of scaling factor

joelle-o-world commented 4 years ago

Perhaps the "scaling factor of 2" referred to by the npm package dct, is the 2 * in:

                N-1
y[k] = 2* sum x[n]*cos(pi*k*(2n+1)/(2*N)), 0 <= k < N.
                n=0

But perhaps not, will need to try it both ways