0

I'm doing an Android project that from voice recorder return fundamental frequency. I calculate frequency with FFT class from:

http://introcs.cs.princeton.edu/java/97data/FFT.java

and Complex Array from:

http://introcs.cs.princeton.edu/java/97data/Complex.java.html.

Here's my code where I calculate frequency:

public double calculateFFT(byte[] signal)
        {           
        final int mNumberOfFFTPoints =1024;
        double mMaxFFTSample;

        double temp;
        Complex[] y;
        Complex[] complexSignal = new Complex[mNumberOfFFTPoints];
        double[] absSignal = new double[mNumberOfFFTPoints/2];

        for(int i = 0; i < mNumberOfFFTPoints; i++){
            temp = (double)((signal[2*i] & 0xFF) | (signal[2*i+1] << 8)) / 32768.0F;
            complexSignal[i] = new Complex(temp,0.0);
        }

        y = FFT.fft(complexSignal); 

        mMaxFFTSample = 0.0;
        int mPeakPos = 0;
        for(int i = 0; i < (mNumberOfFFTPoints/2); i++)
        {
            absSignal[i] = Math.sqrt(Math.pow(y[i].re(), 2) + Math.pow(y[i].im(), 2));

            if(absSignal[i] > mMaxFFTSample)
            {
                mMaxFFTSample = absSignal[i];
                mPeakPos = i;
            } 
        }


        return ((1.0 * sampleRate) / (1.0 * mNumberOfFFTPoints)) * mPeakPos;

    }

where sampleRate=44100 and mNumberOfFFTPoints=1024. From this code I read a lot of values, but I want to get only fundamental frequency, so only value. Can you help me to understand this algoritm, please?

2
  • 1
    This problem is much more complicated than you think, and can only be answered by subjectively deciding what sort of signals you are interested in. A simple solution which might or might not work for you is to either take the strongest component, or something that is low in frequency and strong. May 23, 2014 at 14:57
  • I must try fundamental frequency of human voice, I don't Know if I must consider the maximum value like the value of this fundamental frequency May 23, 2014 at 15:21

1 Answer 1

1

In general, fundamental frequency detection for music or voice is non-trivial. Having said that, depending on your source, you might be able to simplify the problem.

For example if your source is a person singing a single note, with no music or other background sounds in the recording, a modified peak detector might give reasonable results.

The graph below shows the frequency spectrum of a female soprano holding a B-flat-3 (Bb3) note. The fundamental frequency of Bb3 is 233 Hz but the soprano is actually singing a 236 Hz fundamental (the left-most and highest peak.)

Frequency spectrum of female soprano singing B-flat-3 note. Sooeet.com FFT calculator

The graph below shows the frequency spectrum of a female soprano holding an F4 note. The fundamental frequency of F4 is 349 Hz but the soprano is actually singing a 360 Hz fundamental (the left-most peak.)

Frequency spectrum of female soprano singing F4 note. Sooeet.com FFT calculator

However, the above graph also shows one of the challenges of fundamental frequency detection. In this case, the highest peak is not the fundamental, but rather the first harmonic at 714 Hz. Your modified peak detector would have to contend with these cases.

Other possibilities are cepstrum analysis, and autocorrelation.
See these references: Fundamental frequency detection /// Speech Signal Analysis

FFT, graphs, and audio data from Sooeet.com FFT calculator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.