确定某一频率的大小在iPhone上 [英] Determining the magnitude of a certain frequency on the iPhone

查看:131
本文介绍了确定某一频率的大小在iPhone上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么是确定在一个健全的给定频率的幅度最简单/最佳方法。

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

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

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.

我将使用iPhone的麦克风录制的声音。我的猜测是,我将使用音频队列服务进行录制,因为我并不需要记录音频到一个文件中。我使用SDK 4.0,这样我就可以使用任何的加速框架(例如FFT功能)定义的函数如果需要的话。

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.

推荐答案

如果你只需要测试一个频率,你可以计算出的 DFT 。 DFT算法是O(N ^ 2),但FFT算法重用中间结果,实现了DFT计算O(NlogN)。但是,如果你只想要一个频率样本,你可以计算DFT的一个输出样本,并实现O(N)的性能。

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.

这可以通过观察方程的DFT在维基页面做(我还没有打算尝试在此输入),只是计算值Xk对应于感兴趣的频率单一ķ。 k是只对DFT的输出索引。

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.

映射K转化为现实的频率(HZ)(DFT的输出指标)取决于两个因素:

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


  • 采样频率(例如,44100赫兹的CD音响)

  • FFT大小

实时频率被映射为k如下:

Real frequencies are mapped to k as follows:

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是赫兹的频率, N 是FFT的大小和 FS 是采样频率(Hz)。需要注意以下几点:

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


  • k是整数,所以不是所有的频率将映射到一个整数k。找到最接近氏/ li>
  • 如果您需要更多的频率分辨率,增加ñ。

  • 在Fs的采样信号只能够准确地重新present频率可达,但不包括FS / 2(的尼奎斯特速率)。这就是为什么我表明,k以赫兹的映射是只为一半的输出采样不错。我不会进入下半场重新presents什么(它实际上是上半年的镜像一个真正的输入信号)

  • 将DFT / FFT的输出是复杂的。你最有可能想利用这个幅度。

  • 如果您需要计算甚至几DFT输出,它可能是最好只使用FFT功能提供获取,而不是只计算你需要使用DFT输出样本的所有输出样本。其原因是,大多数FFT算法进行大量优化,即使你可能在理论上少做工作,它可能需要比FFT长。你可能只需要这个标杆,看看哪种方法更好。

  • 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

这篇关于确定某一频率的大小在iPhone上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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