How can I get DFT/FFT output frequencies in Hertz?

╄→гoц情女王★ 提交于 2019-12-03 06:23:19

问题


I want to develop musical notes detector as my degree project and I want to do it from scratch. I have written code for ".wav" file which extracts all info from that audio music file and gives me amplitude as a result.

Then I have written a code for DFT - it gives me output as a complex number where one of the axis (real/imaginary) is amplitude/magnitude and other is Phase.

Now the question I want the answer in frequency (in Hertz not in vector) so I can check whether my DFT gives me the proper output or not. How can i convert my DFT output into frequency ?

I have to code this in C language and I don't want to use any built-in library


回答1:


You need to find the peak magnitude then work out the corresponding frequency:

  • calculate the magnitude of each DFT output bin: magnitude = sqrt(re*re+im*im)
  • find the bin with the largest magnitude, call its index i_max.
  • calculate the equivalent frequency of this bin: freq = i_max * Fs / N, here Fs = sample rate (Hz) and N = no of points in FFT.

See this answer for a more detailed explanation of how bin indices and frequency are related.



来源:https://stackoverflow.com/questions/17390677/how-can-i-get-dft-fft-output-frequencies-in-hertz

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!