joelle-o-world / mfcc

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

How does cepstral filtering (liftering) get implemented in python_speech_features? #8

Open joelle-o-world opened 4 years ago

joelle-o-world commented 4 years ago
def lifter(cepstra, L=22):
    """Apply a cepstral lifter the the matrix of cepstra. This has the effect of increasing the
    magnitude of the high frequency DCT coeffs.
    :param cepstra: the matrix of mel-cepstra, will be numframes * numcep in size.
    :param L: the liftering coefficient to use. Default is 22. L <= 0 disables lifter.
    """
    if L > 0:
        nframes,ncoeff = numpy.shape(cepstra)
        n = numpy.arange(ncoeff)
        lift = 1 + (L/2.)*numpy.sin(numpy.pi*n/L)
        return lift*cepstra
    else:
        # values of L <= 0, do nothing
        return cepstra
joelle-o-world commented 4 years ago

This will be fiddly to reimplement given that our version uses a streamed architecture.

joelle-o-world commented 4 years ago

This will be fiddly to reimplement given that our version uses a streamed architecture.

Or perhaps not. It seems like this function is applying the same process to each cepstrum:

lift = []
for(let i=0; i<ncoeff; ++i) {
  lift[i] = 1 + (L/2) * sin(pi * i / L)
}

for each cepstrum {
   for each coefficient = cepstrum[i] {
      cepstrum[i] *= lift[i]
   }
}
joelle-o-world commented 4 years ago

Comes after coefficients have been truncated (ie to 13 from 26)

joelle-o-world commented 4 years ago

Tentatively closing this issue too, although the code really needs checking....