   Getting the pitch from an FFT
  I'm trying to write a tuner (as in guitar, violin, etc). The problem I'm having is that the tuner can't seem to accurately tell what pitch it's hearing. I play E5 on my violin, and the tuner jumps around things like B7, D8, etc. My cheap little Korg tuner easily recognizes the note as an E.When I record my violin playing E5 and run an FFT on it with Audacity, it looks something like this:Look at all those peaks! The very first peak is E5, so that's the one I want. But everything I've read about FFTs said to find the highest peak and declare that to be the pitch, which on this FFT is B7. E5 looks like it's about the 6th or 7th highest peak.So what should I do? Find the first reasonably high peak and use that instead of *the* highest peak? Or am I completely misunderstanding everything? Or should I throw away my violin?   
  I find it strange that the highest peak won't be the note you are playing. Perhaps your microphone is less sensitive in the lower part of the spectrum than at higher frequencies?I can think of two main ideas here:1) Rescale the curve you plotted by multiplying by some decreasing function of frequency, to focus on the lower part of the spectrum, and then find the highest peak.2) After you have computed the FFT, taken squares of the modules of the results and then taken logs (I believe those are the steps that lead to your picture), take another FFT to detect the sequence of peaks. I am not sure exactly how to finish from there, but it shouldn't be too too hard.;  All of those extra peaks are normal, they are the harmonics of the note (multiples of the base frequency). Typically I would guess each one would be slightly less than the preceding one, but your graph might be slightly off due to noise, bad sampling equipment, etc.Stick with the first peak.   ;  Since the harmonics occur at integer multiples of the pitch, this creates periodicity in the power spectrum as well.  So, sometimes people will Fourier transform the power spectrum and use its largest value to tell them what the note is (i.e., they infer what the note is by how far apart the harmonics are spaced).  Wikipedia cepstrum.Also, note that it's key that there be a nonlinear operation in there (like taking the complex absolute value to get power), since the "Fourier transform of Fourier transform" operator is just the "reverse time" operator; i.e.,F{F{x}}(t) = k x(-t)where depending on how your transforms are defined you may have a scaling factor k>0.(This what alvaro's second point was about also.)   ;  Oh yeah!  Also, once when I was playing around with FSK demodulation I decided that a filter bank approach was also very useful:Say I want to detect stuff at 500 Hz.  I'd have running 500Hz sine and cosine waves (which you can generate recursively by just rotating a point iteratively with a rotation matrix); I'd take the L2 inner product of the last N samples of my signal with each of those (which again you can do recursively by adding the new sample and subtracting off the N-1-th sample each timestep) to get two new inner product signals; I'd compute a new signal as the square-root-of-sum-of-squares of these, and THIS signal would be zero when the frequency was not present, one when it was, and ramp up linearly in-between.I had one such filter for each frequency key I had.  This gave me a collection of indicator signals at their outputs.  At any time, I'd assume that the incoming frequency was the one whose indicator function was largest.Everything about this algorithm is recursive, so you're not e.g. taking FFTs of large blocks of samples; that's what I liked about it.   