Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Harmonics count in a music sample

To determine the richness of a sound, I would like to determine the number of harmonics in a sample of music. For that, I'm using Processing with the Minim library which gives me a full spectrum with a FFT. I'm wondering how to count all the peaks in the spectrum produced by the FFT, I'm not even interested in the fundamental frequency.

like image 550
LaurentC Avatar asked Nov 06 '11 09:11

LaurentC


1 Answers

There are many ways of accomplishing this depending on your needs.

If you want to count every peak then you should iterate through all the frequencies in the spectrum remembering whether intensity has been increasing or decreasing. Every time you notice the change in direction from increase to decrease you increment the peak counter. Note however that this will include very faint peaks as well which may or may not be what you need. You can put a minimum limit on how much of an increase and decrease has to happen for a peak to be registered.

Alternatively, you can find a baseline for your signal's intensity (using average in the simplest case) and then count the number of positive outliers (with some configurable minimum deviation from the baseline). You probably will get better results if you modify this approach to use frequency-dependent baseline and minimum to account for gradual drop in intensity at higher frequencies (again, it depends on your particular signal and needs whether this would be useful). One simple way of doing this is to divide your spectrum into bands (small enough to be able to assume more or less flat energy distribution throughout each band) and use different baseline and minimum for each band.

like image 160
Adam Zalcman Avatar answered Oct 06 '22 10:10

Adam Zalcman