我收到錯誤的頻率,我不明白爲什麼我出現錯誤的值。因爲我按照指令進行了計算,接着是計算器。 我已經使用FFT從 http://introcs.cs.princeton.edu/java/97data/FFT.java.html 和複雜的 http://introcs.cs.princeton.edu/java/97data/Complex.java.html使用FFT計算頻率中的錯誤值
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 ...... 請幫我..... 謝謝你..
您應該嘗試使用已知合成正弦曲線運行乾淨的數據。你似乎沒有看到數量,所以你的結果可能只是噪音。如果你使用窗口函數,這並不明顯。 –
什麼是您的採樣率和緩衝區大小?你的輸入信號是什麼樣的? – hotpaw2
@克里斯,因爲我是新來的DSP,請在編程詳解... – Pandian