Hi,
I want to know if it's possible to get the frequency of a sound coming in from the iPhone microphone. I'm not talking here about the recording sampling rate, but the frequency of the sound's waveform. I know it's possible to have access to the sound level via the AudioQueueLevelMeterState struct but I haven't find a way to get the frequency.
This is not an easy task. To get the frequency you'll have to record the audio coming in and use FFTs to analyze it. Google FFT (Fast Fourier Transform) and enjoy.
Hi,
I want to know if it's possible to get the frequency of a sound coming in from the iPhone microphone. I'm not talking here about the recording sampling rate, but the frequency of the sound's waveform. I know it's possible to have access to the sound level via the AudioQueueLevelMeterState struct but I haven't find a way to get the frequency.
Any help would be appreciated.
Your key search terms are: FFT, Wavelet and Autocorrelation.
Read the articles, grok the math and write the code.
Sorry for resurrecting this, but I hope someone can shed light on this.
AurioTouch, apple's sample program is rich with routines demonstrating how to use the audio input, how to buffer it, and how to even FFT it to get the signal in the frequency domain. That's all find, and the internals can be viewed as a very good example and model.
However, the FFT results in an array (called: outMagSpectrum[i]) that provides the relative amplitude of different frequencies for 2048 indexes. But when I read this vector out, it does not correspond to the actual frequency that I feed it in. An A(440) gets only 41, other notes get relatively higher and lower numbers, but none accurate corresponds to the "frequency".
Does anyone know what's the trick to converting these numbers to actual frequencies?
You need to study up on the relationship between sample rate, sample period, frequency range, and frequency resolution. In the example you cited, I assume that the FFT had 4096 samples at 44100 samples per second, which gives a Nyquist frequency of 22050 Hz, which corresponds with the midpoint of the FFT array (index 2048). With those parameters, 440 Hz would come out very close to index 41. Your frequency resolution would be 10.8 Hz per index. You could use interpolation methods to reduce that resolution by about a factor of 10, but in this case I think your sample period (4096/44100 seconds = 93 msec.) is way too short. There is a tradeoff between sample period and FFT resolution. If you want better resolution, you need to use longer sample periods. For example, a sample size of 32768 would give a 0.74 second sample period and a frequency resolution of 1.34 Hz per index. If you are going to use FFTs to measure frequency, you have to take all these things into consideration.