使用FFT计算频率错误的价值观 [英] Wrong values in calculating Frequency using FFT

查看:178
本文介绍了使用FFT计算频率错误的价值观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到错误的频率,我不明白为什么我得到错误values​​.since我已经计算按照指令其次是计算器。
我用从FFT
http://introcs.cs.princeton.edu/java/97data/FFT .java.html
和复杂的
http://introcs.cs.princeton.edu/java/97data/Complex .java.html

I'm getting wrong frequency, I don't understand why i'm getting wrong values.since i have calculating as per instructions followed by stackoverflow. I've used FFT from http://introcs.cs.princeton.edu/java/97data/FFT.java.html and complex from http://introcs.cs.princeton.edu/java/97data/Complex.java.html

audioRec.startRecording();
audioRec.read(bufferByte, 0,bufferSize);
for(int i=0;i<bufferSize;i++){
    bufferDouble[i]=(double)bufferByte[i];    
    }
Complex[] fftArray = new Complex[bufferSize];
    for(int i=0;i<bufferSize;i++){
    fftArray[i]=new Complex(bufferDouble[i],0);
    }
    FFT.fft(fftArray);
double[] magnitude=new double[bufferSize];
for(int i=0;i<bufferSize;i++){
      magnitude[i] = Math.sqrt((fftArray[i].re()*fftArray[i].re()) + (fftArray[i].im()*fftArray[i].im()));
    }
double max = 0.0;
int index = -1;
for(int j=0;j<bufferSize;j++){
    if(max < magnitude[j]){
            max = magnitude[j];
        index = j;
        }
    }
    final int peak=index * sampleRate/bufferSize;
    Log.v(TAG2, "Peak Frequency = " + index * sampleRate/bufferSize);
    handler.post(new Runnable() {
            public void run() {
                textView.append("---"+peak+"---");
            }
        });

我越来越喜欢21000,18976,40222,30283等值...
请帮帮我.....
谢谢。

i'm getting values like 21000,18976,40222,30283 etc... Please help me..... Thank you..

推荐答案

您源$ C ​​$ C几乎是罚款。唯一的问题是,你可以通过全谱,即从0通过Fs的搜索峰/ 2到fs。

Your source code is almost fine. The only problem is that you search for the peaks through the full spectrum, i.e. from 0 via Fs/2 to Fs.

对于任何实数输入信号(你有)FS / 2和FS(=采样频率)之间的频谱是0和FS / 2之间的频谱的精确镜像(我发现的这个漂亮的背景解释)。因此,对于每个频率存在两个峰, 几乎相同的幅度。我在写几乎,因为由于有限的机器precision他们不一定究竟相同。因此,你随机发现在含有奈奎斯特频率以下的频率的频谱的第一半峰值(= FS / 2)或与奈奎斯特频率以上的频率的频谱的第二半

For any real-valued input signal (which you have) the spectrum between Fs/2 and Fs (=sample frequency) is an exact mirror of the spectrum between 0 and Fs/2 (I found this nice background explanation). Thus, for each frequency there exist two peaks with almost identical amplitude. I'm writing 'almost' because due to limited machine precision they are not necessarily exactly identical. So, you randomly find the peak in the first half of the spectrum which contains the frequencies below the Nyquist frequency (=Fs/2) or in the second half of the spectrum with the frequencies above the Nyquist frequency.

如果你想自己纠正错误,停止阅读这里。否则继续:

If you want to correct the mistake yourself, stop reading here. Otherwise continue:

只需更换

for(int j=0;j<bufferSize;j++){

for(int j=0;j<=bufferSize/2;j++){

在源$ C ​​$ C你presented。

in the source code you presented.

P.S。:通常情况下,最好是一个窗口函数应用到分析缓冲液(例如,汉明窗),但对自己的高峰的应用采摘它不会改变结果非常

P.S.: Typically, it is better to apply a window function to the analysis buffer (e.g. a Hamming window) but for your application of peak picking it won't change results very much.

这篇关于使用FFT计算频率错误的价值观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆