0
votes

My app. is displaying the peak frequency of input sound in RPM .. i have array of doubles contains the samples in time domain.

audioRecord.read(buffer, 0, 1024);

Then i did FFT on it .

transformer.ft(toTransform);

using this class Here

then i got the max magnitude of complex values which are the results of FFT

// block size = 1024

double magnitude[] = new double[blockSize / 2];

            for (int i = 0; i < magnitude.length; i++) {
                double R = toTransform[2 * i] * toTransform[2 * i];
                double I = toTransform[2 * i + 1] * toTransform[2 * i * 1];

                magnitude[i] = Math.sqrt(I + R);
            }
            int maxIndex = 0;
            double max = magnitude[0];
            for(int i = 1; i < magnitude.length; i++) {
                if (magnitude[i] > max) {
                    max = magnitude[i];
                    maxIndex = i;
                }
            }

Now i got the index of the max magnitude ... 1 - How can i get the Peak Frequency in details pls ? 2 - Is there any ready function called ComputeFrequency() or getFrequency() ? Thanks in advance :)

1

1 Answers

0
votes

The frequency corresponding to a given FFT bin index is given by:

f = i * Fs / N;

where:

Fs = sample rate (Hz)
N = FFT size
i = bin index

So for your peak index maxIndex and FFT size blockSize the frequency of the peak will be:

f = maxIndex * Fs / blockSize;

See this answer for more details.