Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MelBands malfunctions when number of bands is large (e.g. 128) #142

Closed
justinsalamon opened this issue Sep 17, 2014 · 1 comment
Closed
Labels
Milestone

Comments

@justinsalamon
Copy link

MelBands (when fed with the output of Spectrum) seems to work fine for low numbers of bands, e.g. 24 or 40. But if we increase this number to e.g. 128 or 256, it seems to (mistakenly) always return 0 for specific band numbers.

For instance when setting numberBands = 256, regardless of which audio file I analyze I get 0 in the following bands:

array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 36,
        37, 39, 40, 41, 42, 44, 45, 46, 47, 49, 51, 53, 54, 56, 58, 60, 62,
        64, 67, 69, 71, 74, 79, 82]])

Here are some example spectrograms (of the log-melbands, ignore the y-axis labels):
spec3
spec1
spec2

@justinsalamon
Copy link
Author

update: I think the issue lies with the computation of the start/end spectral bins for each band - if the FFT size is relatively small (e.g. 1024) and the number of mel bands is large (e.g. 128) then for some bands the start and end bin will be the same bin (or adjacent bins), which consequently results in 0 energy being summed at that band.

A practical solution is to use zero padding to increase the number of FFT bins thus avoiding the problem. Nonetheless, it would probably be helpful to run a check when the mel filterbank is created to ensure there are no bands with adjacent or identical start/end bins, and if any are detected print out a warning.

@dbogdanov dbogdanov added this to the future milestone Sep 19, 2014
dbogdanov added a commit that referenced this issue Oct 31, 2016
Similar to #142, throw exception when spectrum resolution is
insufficient. Previous code contained a workaround for such cases
but it seems better to report this issue instead.
dbogdanov added a commit that referenced this issue Mar 28, 2019
- Improve the check for when to throw an exception due to
  insufficient resolution of the input spectrum (#142). Previously,
  rounding was used to find the closet spectrum bins for the start
  and the end position of each filter, but it is better to use
  ceil and floor. Throw the error if all filter coefficients are
  zero instead of only checking if there's enough spectrum bins to
  cover a filter.

- Optimize unit sum normalization. It is faster to do it in the same
  loop when computing filter coefficients for a particular band.

- Some code style improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants