我收到错误的频率,我不明白为什么我出现错误的值。因为我按照指令进行了计算,接着是计算器。 我已经使用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