Determining the fundamental frequency/pitch of a note What I am trying to achieve is getting the fundamental frequency of a note played by an instrument. What I have already done is performing an FFT on a samples of audio file, and here's what I get:  



After that I just tried to find the maximum value in that dataset and I get "4138". Unfortunately, the note being played in the audio file is an E and from internet I know that the E note should have 5274.04 Hz or 2637.02 Hz.
I continued reading some additional info on the internet and found interesting info that in some cases fundamental frequencies could be missing from the sound, so I have tried doing some autocorrelation on the samples I got from the audio file to find the fundamental frequency and I got something like this:      



It looked like a frequency domain for me so I performed FFT on that dataset but got similar results.
Also I have read that some people suggest using HPS (Harmonic Product Spectrum) for finding the fundamental frequency, I have tried that but obviously the result was the same, as the FFT itself didn't change.
P.S. Of course I use Hamming windowing function for samples. The library I use for FFT is JTransforms.
Ok, everything was working quite fine, the only thing that I have missed is another formula that is used to get the "real" frequency from the FFT power spectrum. And the formula is as follows:      


  frequency = indexMax * Fs / L;
  where:
  indexMax - index of the maximum in power spectrum;
  Fs - sampling rate of an audio file;
  L - length of the power spectrum array.       


UPDATE
This approach is working fine for such trivial tasks as making a tuner or something like that, but as 


  robert bristow-johnson        


pointed out, this implementation will, in some cases, ignore the fundamental frequency and potentially show you frequency of one of the harmonics. So a better approach would be        


Autocorrelation
AMDF
ASDF
YIN
Mcleod Pitch method