使用FFT声音输入频率计算 [英] Calculate Frequency from sound input using FFT
问题描述
我的应用程序。正在显示在RPM输入声音的峰值频率..我有双打的数组包含的时域采样。
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);
然后我做FFT就可以了。
Then i did FFT on it .
transformer.ft(toTransform);
然后我得到了复值这是FFT结果的最大震级
then i got the max magnitude of complex values which are the results of FFT
//块大小= 1024
// 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;
}
}
现在我得到了最大规模的指数...
1 - 我怎样才能在细节请波峰的频率?
2 - 有没有叫ComputeFrequency()或getFrequency()函数准备?
在此先感谢:)
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 :)
推荐答案
对应于给定的FFT箱索引的频率由下式给出:
The frequency corresponding to a given FFT bin index is given by:
f = i * Fs / N;
其中:
Fs = sample rate (Hz)
N = FFT size
i = bin index
因此,对于你的峰值指数 maxIndex
和FFT的大小块大小
峰的频率将是:
So for your peak index maxIndex
and FFT size blockSize
the frequency of the peak will be:
f = maxIndex * Fs / blockSize;
请参阅this回答了解更多详情。
这篇关于使用FFT声音输入频率计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!