extract frequency from samples series

I have some series of samples of a signal, I would like to estimate somehow the dominant frequency of the signal. tnx
[131 byte] By [strassaa] at [2007-9-28 7:10:35]
# 1

It's been a long time since I did any signal processing but you might want to try doing a simple zero-crossing count.

For example, count the number of times the signal goes from negative to positive and divide by the number of samples.

int crossings = 0;

for(int idx = 1; idx < sample.length; idx++)

{

if((sample[idx - 1] < 0) && (sample[idx] >= 0))

{

crossings++;

}

}

int frequency = (crossings * sampleRate) / sample.length;

You can doubtlessly get even more complex but this may be good enough for reasonably clean signals.

Hope this helps.

KPSeala at 2007-7-9 18:21:27 > top of Java-index,Other Topics,Algorithms...
# 2
Why don't you use FFT?
dalemitchella at 2007-7-9 18:21:27 > top of Java-index,Other Topics,Algorithms...
# 3
i already tried this solution, and at a first sight it works. The problem is that i do not know if all the signals i am going to use will be as clean as the signals i used for testing. So I am looking for smthing more "robust", but at the same time i do not want to waste ages on this topic.
strassaa at 2007-7-9 18:21:27 > top of Java-index,Other Topics,Algorithms...
# 4

Indeed - zero-crossings will give you the "average" frequency rather than the dominant one.

As suggested, use a fourier transform to get the spectrum corresponding to your signal. The dominant frequency is the one with the highest response.

You might be able to get hold of an FFT routine from mathtools.net or alternatively just wrap up the one listed here:

http://www.nauticom.net/www/jdtaft/JavaFFT.htm

Hope this helps.

KPSeala at 2007-7-9 18:21:27 > top of Java-index,Other Topics,Algorithms...