FFT问题(返回随机的结果) [英] FFT Problem (Returns random results)

查看:193
本文介绍了FFT问题(返回随机的结果)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这有code,但它一直从返回0随机频率约1050请你能帮助我了解为什么发生这种情况。

I've got this code, but it keeps returning random frequencies from 0 to about 1050. Please can you help me understand why this is happening.

我的数据长度为1024,采样率是8192,而数据则是短阵充满了输入数据从话筒。

My data length is 1024, sample rate is 8192, and data is a short array filled with input data from the mic.


float *iSignal = new float[2048];
float *oSignal = new float[2048];
int pitch = 0;

for(x=0;x<=1024;x++) {
    iSignal[x] = data[x];
}

fft(iSignal,oSignal,1024); //Input data, output data, length of input and output data

for(int y=0;y< 2048;y+=2) {
if((pow(oSignal[y],2)+pow(oSignal[y+1],2))>(pow(oSignal[pitch],2)+pow(oSignal[(pitch)+1],2))) {
    	pitch = y;
    }
}

double pitchF = pitch / (8192.0/1024);
printf("Pitch: %f\n",pitchF);

谢谢,

尼尔。

编辑:改变了code,但它仍然返回随机频率

Changed the code, but it's still returning random frequencies.

推荐答案

假设 oSignal 以这样的方式填充有复数,即实部和虚部备用,它或许有助于改变

Assuming oSignal is filled with complex numbers in such a way, that real and imaginary parts alternate, it might help to change

for(int y=0;y< 8191;y++)

for(int y=0;y< 8191;y+=2)

编辑:我甚至没有注意到,你只能通过1024个样本。你必须通过成许多个时间域采样一样会有频域采样,在您的案件4096。

I didn't even notice that you're passing only 1024 samples. You must pass as many time-domain samples as there will be frequency-domain samples, in your case 4096.

编辑:一件事:你显然试图找到的东西基本频率。除非某事是计算机产生的音调或人类哨子(这两者都是非常纯音),你可能会通过的结果感到失望。您发布的简单的方法几乎适用于长笛。

One more thing: you're obviously trying to find the base frequency of something. Unless that something is a computer generated tone or a human whistle (both of which are very pure tones), you might be disappointed by the result. The simple method you posted barely works for flute.

编辑:对于语音和吉他你的运气了。我写了程序的前一段时间,显示频域,尝试一下,你会看到这个问题。也有源使用,如果你有兴趣。

For voice and guitar you're out of luck. I wrote a program some time ago that displays the frequency domain, try it out, you'll see the problem. There are also sources available, if you're interested.

最后修改:您可能需要阅读基音检测维基百科文章。集中在时域的方法。

Final edit: You might want to read the Wikipedia article on pitch detection. Concentrate on time-domain approaches.

这篇关于FFT问题(返回随机的结果)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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