tags:

views:

1306

answers:

4

I'm trying to write a simple tuner (no, not to make yet another tuner app), and am looking at the AurioTouch sample source (has anyone tried to comment this code??).

My worry is that aurioTouch doesn't seem to actually work very well when looking at the frequency domain graph. I play a single note on an instrument and I don't see a nicely ordered, small, set of frequencies with one string peak at the appropriate frequency of the note.

Has anyone used aurioTouch enough to know whether the underlying code is functional or whether it is just a crude sample?

Other options I have are to use FFTW or KISS FFT. Anyone have any experience with those?

Thanks.

+2  A: 

FFTs use frequency bins and the bin frequency width is based on the FFT parameters. To find a frequency you will need to record it sampled at a rate at least twice the highest frequency present in the sample. Then find the time between the cycles. If it is not a pure frequency this will of course be harder.

zaph
But does aurioTouch do it correctly? Also, yo usay to find the time between cycles. I won't have to do that if I do an FFT, the FFT, as you also mentioned does that for me. And my experience with FFTs and a musical note is that one bin will show a higher value, and that would be the fundamental frequency of the note. I assume all musical notes to have an easily recognizable fundamental frequency, otherwise our ears would reject them as being off-key.
mahboudz
The width of the frequency bibs are quite wide so they will not accurately provide the frequency accurately. An FFT is not a Fourier transform, just a fast approximation. How accurately do you want to know the frequency? Compare that with the frequency bin widths.
zaph
Musical notes. http://www.phy.mtu.edu/~suits/notefreqs.html 10% separation at 100Hz or so?
mahboudz
+2  A: 

aurioTouch looks weird because the frequency axis is on a linear scale. It's very difficult to interpret FFT output when the x-axis is anything other than a logarithmic scale (traditionally log2).

If you can't use aurioTouch's integer-FFT, check out my library: http://github.com/alexbw/iPhoneFFT

It uses double-precision, has support for multiple window types, and implements Welch's method (which should give you more stable spectra when viewed over time).

@zaph, the FFT does compute a true Discrete Fourier Transform. It is simply an efficient algorithm that takes advantage of the bit-wise representation of digital signals.

alexbw
Thanks! I'm going to check out your code. Do you know if aurioTouch is a derivative of Ooura's FFT?
mahboudz
aurioTouch implements its own FFT.When I say "Ooura's FFT", I'm referring to the code that Prof. Ooura wrote: http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html. My project is a wrapper around it, making it (a little) more usable for the ObjC programmer.The algorithm that both codes use is almost certainly very similar. To my knowledge, when using power-of-two-length signals, there are not many variants on the original FFT algorithm.
alexbw
Is there a sample xcode project illustrating the use of iPhoneFFT? I cant seem to wire it up in my project.
Matthew
A: 

Hi,

I am using Ooura FFT to compute the FFT of acceleromter data. I do not always obtain the correct spectrum. For some reason, Ooura FFT produces completely wrong results with spectral magnitudes of the order 10^200 across all frequencies.

Yan
+2  A: 

You're expecting the wrong thing!!

Not the library's fault

Whether the library produces it properly or not, you're looking for a pattern that rarely actually exists in real-life sounds. Only a perfect sine wave, electronically generated, will cause an even partway discrete appearing 'spike' in the freq. graph. If you don't believe it try firing up a 'spectrum analyzer' visualization in winamp or media player. It's not so much the PC's fault.

Real sound waves are complicated animals

Picture a sawtooth or sqaure wave in your mind's eye. those sharp turnaround - corners or points on the wave, look like tons of higher harmonics to the FFT or even a real fourier. And if you've ever seen a real 'sqaure wave/sawtooth' on a scope, or even a 'sine wave' produced by an instrument that is supposed to produce a sinewave, take a look at all the sharp nooks and crannies in just ONE note (if you don't have a scope just zoom way in on the wave in audacity - the more you zoom, the higher notes you're looking at). Yep, those deviations all count as frequencies.

It's hard to tell the difference between one note and a whole orchestra sometimes in a spectrum analysis.

But I hear single notes!

So how does the ear do it? It considers the entire waveform. Then your lower brain lies to your upper brain about what the input is: one note, not a mess of overtones.

You can't do it as fully, but you can approximate it via 'training.'

Approximation: building some smarts

PLAY the note on the instrument and 'save' the frequency graph. Do this for notes in several frequency ranges, or better yet all notes.

Then interpolate the notes to fill in gaps (by 1/2 or 1/4 steps) by multiplying the saved graphs for that instrument by 2^(1/12) (or 1/24 for 1/4 steps, etc).

Figure out how to store them in a quickly-searchable data structure like a BST or trie. Only it would have to return a 'how close is this' score. It would have to identify the match via proportions of frequencies as well, in case it came in different volumes.

Using the smarts

Next time you're looking for a note from that instrument, just take the 'heard' freq graph and find it in that data structure. You can record several instruments that make different waveforms and search for them too. If there are background sounds or multiple notes, take the closest match. Then if you want to identify other notes, 'subtract' the found frequency pattern from the sampled one, and rinse, lather repeat.

It won't work by your voice...

If you ever tried to tune yourself by singing into a guitar tuner, you'll know that tuners arent that clever. Of course some instruments (voice esp) really float around the pitch and generate an ever-evolving waveform (even without somebody singing).

What are you trying to accomplish?

You would not have to totally get this fancy for a 'simple' tuner app, but if you're not making just another tuner app them I'm guessing you actually want to identify notes (e.g., maybe you want to autogenerate midi files from songs on the radio ;-)

Good luck. I hope you find a library that does all this junk instead of having to roll your own.

FastAl