Audio beacon is generating different frequency between 18 khz to 19 khz.I'm trying to record all frequency using AudioTrack Api.I refered this link How to get frequency from fft result?. I'm getting all data is 0 after apply hanning window function.1)how to apply hanning window? 2)how to filter frequency?3) I record different range frequency audio and save it in .wav formate.I'm reading that audio file and convert into frequency.But i'm getting high frqeuency only.How to get multiple peak frequency?
int fftSize = 1024;
public void startRecord() {
short[] bytebuff = new short[2 * fftSize];
while (started) {
int bufferReadResult = audioRecord.read(bytebuff, 0, bytebuff.length);
if (bufferReadResult >= 0) {
fft(bytebuff);
}
}
}
public void fft(short[] bufferByte) {
int N = bufferByte.length;
DoubleFFT_1D fft1d = new DoubleFFT_1D(N);
double[] fft = new double[N * 2];
double[] magnitude = new double[N / 2];
for (int i = 0; i < N; i++) {//Hann window function
bufferByte[i] = (byte) (bufferByte[i] * 0.5 * (1.0 - Math.cos(2.0 * Math.PI * i / (bufferByte.length))));//here i'm getting all data is zero.
}
for (int i = 0; i < N - 1; ++i) {
fft[2 * i] = bufferByte[i];
fft[2 * i + 1] = 0;
}
fft1d.complexForward(fft);
// calculate power spectrum (magnitude) values from fft[]
for (int i = 0; i < (N / 2) - 1; i++) {
double real = fft[2 * i];
double imaginary = fft[2 * i + 1];
magnitude[i] = Math.sqrt(real * real + imaginary * imaginary);
}
double max_magnitude = -1;
int max_index = -1;
for (int i = 0; i < (N / 2) - 1; i++) {
if (magnitude[i] > max_magnitude) {
max_magnitude = magnitude[i];
max_index = i;
}
}
int freq = max_index * 44100 / N;
Log.e("AudioBEacon", "---" + freq);
}