如何从FFT结果的频率? [英] How to get frequency from fft result?

查看:194
本文介绍了如何从FFT结果的频率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的Andr​​oid手机上记录的数据数组[1024]从我的麦克风,通过一维真实数据的转发DFT(设置进一步的1024位为0),通过它。我救了数组到一个文本文件,并重复了这个8次。

I have recorded an array[1024] of data from my mic on my Android phone, passed it through a 1D forward DFT of the real data (setting a further 1024 bits to 0). I saved the array to a text file, and repeated this 8 times.

我回到16384结果。我在Excel中打开文本文件,并提出了图表看是什么样子(阵列,Y的= X =索引号的大小返回)。还有一些巨大的峰值(正面和负面的)的幅度约110,232,小尖峰继续以那种方式,直到大约1817年和1941年,其中尖峰变大一次,然后再次下降。

I got back 16384 results. I opened the text file in Excel and made a graph to see what it looked like(x=index of array, y=size of number returned). There are some massive spikes (both positive and negative) in magnitude around 110, 232, and small spikes continuing in that fashion until around 1817 and 1941 where the spikes get big again, then drop again.

我的问题是,无论我找上它提到gettng的实部和虚数的主题的帮助,我只有一维数组,我得到了我从彼得Wendykier的类所使用的方法后面:

My problem is that wherever I look for help on the topic it mentions gettng the real and imaginary numbers, I only have a 1D array, that I got back from the method I used from Piotr Wendykier's class:

DoubleFFT_1D.realForwardFull(audioDataArray); // from the library JTransforms.

我的问题是:什么是我需要做的,这些数据返回的频率? 声音记录的是我对我的吉他底部的字符串(第5 FRET)发挥着A(在大约440Hz的)。

My question is: What do I need to do to this data to return a frequency? The sound recorded was me playing an 'A' on the bottom string (5th fret) of my guitar (at roughly 440Hz) .

推荐答案

复杂的数据交错,以在甚至在奇数索引的索引和虚部真正的成分,即真正成分是在指数 2 * I ,虚组件处于指数 2 * I + 1

The complex data is interleaved, with real components at even indices and imaginary components at odd indices, i.e. the real components are at index 2*i, the imaginary components are at index 2*i+1.

要获得频谱索引i的大小,你想要的:

To get the magnitude of the spectrum at index i, you want:

re = fft[2*i];
im = fft[2*i+1];
magnitude[i] = sqrt(re*re+im*im);

然后就可以绘制幅度[我]对于i = 0到N / 2来获得的功率谱。根据音频输入的性质,你应该看到在频谱一个或多个峰。

Then you can plot magnitude[i] for i = 0 to N / 2 to get the power spectrum. Depending on the nature of your audio input you should see one or more peaks in the spectrum.

要得到任何给定的峰值的大致频率,你可以转换峰的指标如下:

To get the approximate frequency of any given peak you can convert the index of the peak as follows:

freq = i * Fs / N;

其中:

freq = frequency in Hz
i = index of peak
Fs = sample rate (e.g. 44100 Hz or whatever you are using)
N = size of FFT (e.g. 1024 in your case)

请注意:如果你还没有previously应用合适的窗函数到时域的输入数据,然后你会得到一定数额的频谱泄漏和功率谱将看起来相当抹黑。

Note: if you have not previously applied a suitable window function to the time-domain input data then you will get a certain amount of spectral leakage and the power spectrum will look rather "smeared".

要在此进一步扩大,这里是伪$ C $下一个完整的例子,我们采取的音频数据,并确定最大峰值频率:

To expand on this further, here is pseudo-code for a complete example where we take audio data and identify the frequency of the largest peak:

N = 1024          // size of FFT and sample window
Fs = 44100        // sample rate = 44.1 kHz
data[N]           // input PCM data buffer
fft[N * 2]        // FFT complex buffer (interleaved real/imag)
magnitude[N / 2]  // power spectrum

capture audio in data[] buffer
apply window function to data[]

// copy real input data to complex FFT buffer
for i = 0 to N - 1
  fft[2*i] = data[i]
  fft[2*i+1] = 0

perform in-place complex-to-complex FFT on fft[] buffer

// calculate power spectrum (magnitude) values from fft[]
for i = 0 to N / 2 - 1
  re = fft[2*i]
  im = fft[2*i+1]
  magnitude[i] = sqrt(re*re+im*im)

// find largest peak in power spectrum
max_magnitude = -INF
max_index = -1
for i = 0 to N / 2 - 1
  if magnitude[i] > max_magnitude
    max_magnitude = magnitude[i]
    max_index = i

// convert index of largest peak to frequency
freq = max_index * Fs / N

这篇关于如何从FFT结果的频率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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