JuliaDSP / MFCC.jl

Mel Frequency Cepstral Coefficients calculation for Julia
BSD 2-Clause "Simplified" License
33 stars 18 forks source link

`mfcc` returns NaNs when signal contains zeros #24

Closed nantonel closed 4 years ago

nantonel commented 4 years ago

I suppose this behaviour should be avoided:

julia> using MFCC

julia> X, = mfcc(zeros(1000));

julia> any(isnan.(X))
true

Adding a small constant fixes the problem:

julia> X, = mfcc(zeros(1000).+eps());

julia> any(isnan.(X))
false

not sure this is the common practice though...

lostanlen commented 4 years ago

it would be more numerically stable to clip than to add a constant. Or else consider the log1p function.

Librosa clips to -80 dB by default https://github.com/librosa/librosa/blob/ceb862f6117f959bda0ecc04f6891ea2c80b0ce0/librosa/core/spectrum.py#L1447

davidavdav commented 4 years ago

See https://github.com/JuliaDSP/MFCC.jl/pull/14