如何使用 C 中的 FFTW 从 PortAudio 的样本中提取频率信息

发布于 2024-09-05 19:52:03 字数 353 浏览 4 评论 0原文

我想制作一个程序,使用 PortAudio 记录音频数据(我已经完成了这部分),然后显示所记录音频的频率信息(现在,我想显示每组样本的平均频率)当他们进来时)。

根据我所做的一些研究,我知道我需要进行 FFT。所以我在 google 上搜索了一个用 C 语言编写的库,并找到了 FFTW。

然而,现在我有点失落了。我到底应该如何处理我记录的样本以从中提取一些频率信息?我应该使用哪种 FFT(我假设我需要真实的一维数据?)?

一旦我进行了 FFT,我如何从它提供给我的数据中获取频率信息?

编辑:我现在还找到了自相关算法。是不是更好了?更简单吗?

提前非常感谢,抱歉,我对此完全没有经验。我希望它至少有一点意义。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芸娘子的小脾气 2024-09-12 19:52:03

要将音频样本转换为功率谱:

  • 如果您的音频数据是整数数据,则将其转换为浮点,
  • 选择 FFT 大小(例如 N=1024),
  • 应用 窗口函数到 N 个数据样本(例如 Hanning)
  • 使用大小为 N 的实数到复数 FFT 生成频域数据
  • 计算复数频域数据的幅度 (magnitude = sqrt(re^2 + im^ 2))
  • 可选择将幅度转换为对数刻度 (dB) (magnitude_dB = 20*log10(magnitude))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文