Hi, I want to implement a simple application for tuning a guitar. For that I need to know how to extract the frequency of the incoming microphone data. Any hints or suggestions on how to do that?
Thanks in advance
Printable View
Hi, I want to implement a simple application for tuning a guitar. For that I need to know how to extract the frequency of the incoming microphone data. Any hints or suggestions on how to do that?
Thanks in advance
There's no simple way to do this. Pure sine waves are rare in the real world; the sound emitted by a single guitar note is actually a fairly complex composite of many sine waves, although your ear easily picks up the fundamental frequency.
Basically, you need to run your sampled sound through a Fourier transform. This will convert the time-domain signal recorded by your microphone into a frequency-domain signal, with each individual component sine wave in the original signal represented as a sharp "spike". In general, you would select the spike closest to zero, since this is normally the fundamental, although for some sound emitters (bells, for instance) the situation is more complex and you should find the tallest spike, which may occur farther from zero than others. With proper scaling, the location of the spike corresponds directly to the frequency of that component.
A good C-based library for performing Fourier transforms is FFTW. It's free, well documented and ought to compile just about anywhere. Note that if you're unfamiliar with the mathematics of signal processing, the documentation may be a somewhat rough climb.