确定 iPhone 上特定频率的大小

发布于 2024-09-03 16:37:19 字数 278 浏览 1 评论 0原文

我想知道确定声音中给定频率的幅度的最简单/最好的方法是什么。

据我了解,FFT 函数将返回信号中所有频率的幅度。我想知道如果我只关心特定频率是否可以使用任何快捷方式。

我将使用 iPhone 麦克风来录制音频。我的猜测是,我将使用音频队列服务进行录制,因为我不需要将音频录制到文件中。我使用的是 SDK 4.0,因此如果需要,我可以使用 Accelerate 框架中定义的任何函数(例如 FFT 函数)。

更新: 我根据康拉德的建议更新了问题以使其更加清晰。

I'm wondering what's the easiest/best way to determine the magnitude of a given frequency in a sound.

It's my understanding that a FFT function will return the magnitudes of all frequencies in a signal. I'm wondering if there is any shortcut I could use if I'm only concerned about a specific frequency.

I'll be using the iPhone mic to record the audio. My guess is that I'll be using the Audio Queue Services for recording since I don't need to record the audio to a file. I'm using SDK 4.0, so I can use any of the functions defined in the Accelerate framework (e.g. FFT functions) if needed.

Update:
I updated the question to be more clear as per Conrad's suggestion.

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

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

发布评论

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

评论(1

悲念泪 2024-09-10 16:37:19

如果只需要测试一个频率,则只需计算DFT的对应点即可。 DFT 算法的复杂度为 O(N^2),但 FFT 算法重用中间结果,以实现 DFT 计算的 O(NlogN)。但是,如果您只需要一个频率样本,则只需计算 DFT 的一个输出样本即可实现 O(N) 性能。

这可以通过查看 wikipedia 页面 上的 DFT 方程来完成(我不是甚至尝试在此处输入)并计算与感兴趣的频率相对应的单个 k 的 Xk 。 k 只是 DFT 输出的索引。

将 k(DFT 输出的索引)映射到实际频率 (Hz) 取决于两件事:

  • 采样频率(例如,CD 音频为 44100 Hz)
  • FFT 大小

实际频率映射到 k,如下所示:

F = k*Fs/N  for k = 0 ... N/2-1 ((N-1)/2 for odd N)

k = F*N/Fs  for F = 0Hz ... Fs/2-Fs/N

其中 F< /code> 是以 Hz 为单位的频率,N 是 FFT 大小,Fs 是采样频率 (Hz)。需要注意的一些事情:

  • k 是一个整数,因此并非所有频率都会映射到整数 k。找到最接近的 k
  • 如果需要更高的频率分辨率,请增加 N。
  • 以 Fs 采样的信号只能准确表示高达 Fs/2 的频率,但不包括 Fs/2 (奈奎斯特率)。这就是为什么我表明从 k 到 Hz 的映射仅适用于一半的输出样本。我不会讨论后半部分代表什么(它实际上是真实输入信号的前半部分的镜像)。DFT
  • /FFT 的输出很复杂。您很可能想要了解其严重程度。
  • 如果您需要计算甚至几个 DFT 输出,最好仅使用可用的 FFT 函数并获取所有输出样本,而不是使用 DFT 只计算所需的输出样本。原因是大多数 FFT 算法都经过了大量优化,因此即使理论上您可能做的工作较少,但它可能比 FFT 花费更长的时间。您可能只需要对此进行基准测试,看看哪种方法更好。

为了简单起见,我省略了很多其他细节,这些细节对您的应用程序来说并不重要

If you only need to test for one frequency, you can just calculate the corresponding point of the DFT. The DFT algorithm is O(N^2), but the FFT algorithm reuses intermediate results to achieve O(NlogN) for computation of the DFT. However, if you want only one frequency sample, you can just calculate one output sample of the DFT and achieve O(N) performance.

This can be done by looking at the equation for the DFT on the wikipedia page (I'm not even going to try to type it here) and just calculate Xk for a single k corresponding to the frequency of interest. k is just the indexing on the output of the DFT.

Mapping k (indexes of the DFT output) into real frequencies (Hz) depends on two things:

  • Sampling frequency (for example, 44100 Hz for CD Audio)
  • FFT size

Real frequencies are mapped to k as follows:

F = k*Fs/N  for k = 0 ... N/2-1 ((N-1)/2 for odd N)

or

k = F*N/Fs  for F = 0Hz ... Fs/2-Fs/N

where F is the frequency in Hz, N is the FFT size, and Fs is the sampling frequency (Hz). Some things to note:

  • k is an integer, so not all frequencies will map to an integer k. Find the closest k
  • If you need more frequency resolution, increase N.
  • Signals sampled at Fs are only able to accurately represent frequencies up to, but not including Fs/2 (Nyquist rate). This is why I showed that the mapping from k to Hz is only good for half the output samples. I will not go into what the second half represents (it will actually be a mirror image of the first half for a real input signal)
  • The output of the DFT/FFT is complex. You most likely want to take the magnitude of this.
  • If you need to compute even a few DFT outputs, it may be better to just use the FFT function available and get all the output samples instead of calculating just the output samples you need using the DFT. The reason is that most FFT algorithms are heavily optimized so even though you may be theoretically doing less work, it may take longer than the FFT. You would probably just have to benchmark this to see which approach is better.

I've left out quite a few other details for simplicity's sake that shouldn't matter for your application

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