如何使用 C 中的 FFTW 从 PortAudio 的样本中提取频率信息 [英] How to extract frequency information from samples from PortAudio using FFTW in C

查看:17
本文介绍了如何使用 C 中的 FFTW 从 PortAudio 的样本中提取频率信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to make a program that would record audio data using PortAudio (I have this part done) and then display the frequency information of that recorded audio (for now, I'd like to display the average frequency of each of the group of samples as they come in).

From some research I've done, I know that I need to do an FFT. So I googled for a library to do that, in C, and found FFTW.

However, now I am a little lost. What exactly am I supposed to do with the samples I recorded to extract some frequency information from them? What kind of FFT should I use (I assume I'd need a real data 1D?)?

And once I'd do the FFT, how do I get the frequency information from the data it gives me?

EDIT : I now found also the autocorrelation algorithm. Is it better? Simpler?

Thanks a lot in advance, and sorry, I have absolutely no experience if this. I hope it makes at least a little sense.

解决方案

To convert your audio samples to a power spectrum:

  • if your audio data is integer data then convert it to floating point
  • pick an FFT size (e.g. N=1024)
  • apply a window function to N samples of your data (e.g. Hanning)
  • use a real-to-complex FFT of size N to generate frequency domain data
  • calculate the magnitude of your complex frequency domain data (magnitude = sqrt(re^2 + im^2))
  • optionally convert magnitude to a log scale (dB) (magnitude_dB = 20*log10(magnitude))

这篇关于如何使用 C 中的 FFTW 从 PortAudio 的样本中提取频率信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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