title: Autocorrelation returns random results with mic input (using a high pass filter)
body: <p>Sorry to ask a similar question to the one i asked before (<a href="https://stackoverflow.com/questions/1351381/fft-problem-returns-random-results">FFT Problem (Returns random results)</a>), but i've looked up pitch detection and autocorrelation and have found some code for pitch detection using autocorrelation.</p>
  
  <p>Im trying to do pitch detection of a users singing. Problem is, it keeps returning random results. I've got some code from <a href="http://code.google.com/p/yaalp/" rel="nofollow noreferrer">http://code.google.com/p/yaalp/</a> which i've converted to C++ and modified (below). My sample rate is 2048, and data size is 1024. I'm detecting pitch of both a sine wave and mic input. The frequency of the sine wave is 726.0, and its detecting it to be 722.950820 (which im ok with), but its detecting the pitch of the mic as a random number from around 100 to around 1050.</p>
  
  <p>I'm now using a High pass filter to remove the DC offset, but it's not working. Am i doing it right, and if so, what else can i do to fix it? Any help would be greatly appreciated!</p>
  
  <p>(Fixed)</p>
  
  <p>Thanks,</p>
  
  <p>Niall.</p>
  
  <p>Edit: Changed the code to implement a high pass filter with a cutoff of 30hz (from <a href="https://stackoverflow.com/questions/35530/what-are-high-pass-and-low-pass-filters">What Are High-Pass and Low-Pass Filters?</a>, can anyone tell me how to convert the low-pass filter using convolution to a high-pass one?) but it's still returning random results. Plugging it into a VST host and using VST plugins to compare spectrums isn't an option to me unfortunately.</p>
  
  <p>Edit: Fixed, thanks for everyones help, but I never got it to work, now using new code.</p>