I was using this pseudo code
for (int i = 0; i < bufferSize /2 ; i++)
{
if (magnitude[i] > max_magnitude)
{
count++;
max_magnitude = magnitude[i];
max_magnitude_index = i;
}
}
my samplerate 48000 and buffersize = 2048*2*2
(for avoiding error when calculation in fft return error (n != 2)
When I am trying to calculate the frequency , then magnitude picks some times goes wrong and I get wrong data , like 45000, 33000.
in logcat its shown as following:
MAX MAGNITUDE INDEX = 43 FREQ : 503 count = 12
MAX MAGNITUDE INDEX = 43 FREQ : 503 count = 6
MAX MAGNITUDE INDEX = 43 FREQ : 503 count = 11
MAX MAGNITUDE INDEX = 4053 FREQ : 47496 count = 10
MAX MAGNITUDE INDEX = 4053 FREQ : 47496 count = 14
for generating tons I am using onlinegenerator. I set it to 500 and test it.
and i cant understand how to avoid these errors in magnitude calculations. Whats wrong ? code work good, i can get frequency of sound from 100 to 19500 (cant test more then 19500 hertc) . But picks of magnitude sometimes very strange.