2013-04-17 61 views
1

我的應用程序。以RPM顯示輸入聲音的峯值頻率。我有雙倍數組包含時域中的採樣。使用FFT計算聲音輸入的頻率

audioRecord.read(buffer, 0, 1024); 

然後我做了FFT。

transformer.ft(toTransform); 

使用這個類Here

然後我得到複數值其是FFT

的結果

//塊大小= 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()的函數? 感謝提前:)

回答

0

對應於給定FFT單元索引頻率由下式給出:

f = i * Fs/N; 

其中:

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

因此,對於你的峯值指數maxIndex和FFT的大小blockSize的峯的頻率將爲:

f = maxIndex * Fs/blockSize; 

有關更多詳細信息,請參閱this answer

+0

非常感謝您的回覆並幫助我,是正確還是應該使用RealDoubleFFT類進行FFT變換? – Fareed

+0

這是RealDoubleFFT類的鏈接 [鏈接](http://herschel.esac.esa.int/hcss-doc-10.0/load/hcss_drm/api/herschel/ia/numeric/toolbox/xform/util/RealDoubleFFT .html) – Fareed

+0

請給我一個答案..這是這個項目中的最後一個提示,我認爲:) – Fareed