开发者

Tutorial on Autocorrelation? [closed]

开发者 https://www.devze.com 2023-03-22 15:52 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

Ive recently been considering using Autocorrelation for Pitch Detection. However, I am finding it difficult on finding good sources of where to learn autocorrelation, by this I mean sources that make it easy to understand autocorrelation step-by-step.

Im not that very good a programmer yet and also not really big on formulas so the sources that I find are really difficult to understand.

Basically, what I know now is the concept of autocorrelation is like a compare-and-contrast method of a signal? But I would really appreciate it if I can have more understanding of the autocorrelation algorithm.

Thank you very much!

UPDATE: Here is a sample code I got from a site. Maybe you can use it as reference. Ive tested this code and it does return the correct pitch properly (albeit there are some incorrect ones here and there)

maxOffset = sampleRate / minFreq;
minOffset = sampleRate / maxFreq;

for (int lag = maxOffset; lag >= minOffset; lag--)
{
   float corr = 0; // this is calculated as the sum of squares
   for (int i = 0; i < framesize; i++)
   {
      int oldIndex = i - lag;
      float sample = ((oldIndex < 0) ? prevBuffer[frames + oldIndex] : buffer[oldIn开发者_如何学运维dex]);
      corr += (sample * buffer[i]);
   }

   if (corr > maxCorr)
   {
      maxCorr = corr;
      maxLag = lag;
   }
}

return sampleRate / maxLag;


Here's what I hope is a simple explanation.

Firstly consider how sonar works - you send out a known signal and then compare a received signal with the original - the signals are compared over a range of possible delays and the best match corresponds to the round trip time for the reflected signal.

OK - now think of a periodic signal, such as a sustained middle C note on a piano. If you compare the note with itself at a range of different delays you will get a match for any delay which corresponds to the pitch period of the note. This is essentially what autocorrelation is: comparing a signal with itself over a range of possible delays and getting a peak wherever signal matches the delayed version of itself. For most musical notes the first such peak corresponds to exactly one pitch period, and so you can deduce the pitch from this (pitch or frequency = reciprocal of delay).

0

精彩评论

暂无评论...
验证码 换一张
取 消