Groot
Groot

Reputation: 14251

Frequency detection on iPhone

One part of an app I'm currently working on will work as a tuner. I want to be able to use the iPhone to display the peak frequency of a signal given by the user. I have used the SCListener which worked very good on the iPhone simulator. However when I tried it on a real device it didn't.

Forums suggests that I use apple FFT and accelerate Framework to do this but it seems overly complicated. I would really appreciate if anyone that has programmed a tuner or similar could point me in a good direction!

Thanks!

Upvotes: 1

Views: 1971

Answers (4)

Groot
Groot

Reputation: 14251

Thanks for all the answers! I had missed a part in my code to make the SC listener work on the device as well but are now trying to change it for Apples own AVAudioRecorder since it is suppose to be a lot faster. The problem was that the cocos2d framework blocked the recording of sounds until you called for a method that allowed this. It works like a charm now! :) Thanks again!

Upvotes: 0

Redeye
Redeye

Reputation: 1602

From previous experience doing this :

  1. FFT isn't as always as accurate as you might think, and is computationally expensive
  2. Autocorrelation gives pretty good results
  3. If you have a strong fundamental, zero-crossing can be very accurate and is very computationally efficient (just count the number of times the signal crosses zero over a period of time, f = (2 x time period in seconds)/(number of zero crossings)\

Hope that helps.

Upvotes: 1

hotpaw2
hotpaw2

Reputation: 70673

Peak frequency is often different from the pitch frequency that one would want a (music) tuner to estimate. Look up pitch estimation.

Upvotes: 2

jbat100
jbat100

Reputation: 16827

There is a related post on dsp.stackexchange. It suggests that autocorrelation will work better than FFT at finding the fundamental, if the fundamental is lower in amplitude than the harmonics. Autocorrelation is slightly less tricky than FFT. The accelerate framework will come to your help there again for that. However this is not the case usually.

I don't know of any out of the box solutions which will do all the work for you. The vDSP Programming Guide has specific worked examples for real FFTs which you might want to look into, it takes some getting used to, but it's worth it really. FFT seems like the most logical first step in peak frequency extraction I'm afraid. Most sources seem also to suggest that applying a windowing function to the time domain signal before running the FFT is critical (or you will get high frequency artifacts because of discontinuities at the extremities).

Also you might want to check out this related SO post.

Upvotes: 4

Related Questions