How get cross-correlation peak and based on it calculate correlation score for similarity of two audio samples. SO far I've

  1. FFT two samples
  2. complex conjugate second
  3. multiply results
  4. IFFT
  5. cross-correlate with itself(autocorrelate)

Thanks for any advice

  • 3
    $\begingroup$ You've described how to compute the cross-correlation using an FFT. I'm not sure what your question is. If you want a 'similarity score' you could try to use the correlation coefficient. $\endgroup$
    – Matt L.
    Jul 2, 2013 at 18:59
  • $\begingroup$ In my app I need to know are two words same. I have recorded one and need to detect second real time. And now I don't know what to do next and what I really need to compare mg, amplitude or something else. $\endgroup$
    – user4947
    Jul 3, 2013 at 7:26
  • 2
    $\begingroup$ The answers posted here are correct, but cross-correlation is not relevant to what you ultimately want to do. $\endgroup$ Jul 7, 2013 at 19:40
  • $\begingroup$ so have you any suggestions pichenettes? That will be great $\endgroup$
    – user4947
    Jul 11, 2013 at 8:23

2 Answers 2


As Matt stated, you should use the correlation coefficient!.

Points 1 to 4 calculate the crosscorrelation. From that you have to find the highest peak (or lowest, if it has a higher absolute value). This value is the value of the nominator.

The denominator consists of the two autocorrelation values. Those are obtained by using the same algorithm where both signals are the equal. Here the peak should be in the middle (t=0) as already stated by welcomedungeon. Taking the square root of both autocorrelation values and multiplying them, gives the denominator.

Edit: Maybe this description is more clear:


The apostroph means conjugate complex.

Edit: Two examples with Matlab code:

Using the same signal:

x = rand(1000,1)-0.5;

gives 1;

Using a sine and a cosine, should also give 1 because they are delayed versions of each other:

x = sin([0:pi/100:10*pi]);
y = cos([0:pi/100:10*pi]);

gives approximately 1

Using windowing before transformation to frequency domain should improve results.

  • $\begingroup$ Hi thanks for answer, but when I use correlation coefficient I don't get value in 0-1 interval. As I think I do something wrong, I calculate correlation coefficient in ffts, is it right or not? Sorry if my questions are stupid:), I'm just new in audio processing, fft stuff $\endgroup$
    – user4947
    Jul 4, 2013 at 7:28
  • $\begingroup$ Twonky can you please explain which are two autocorrelation values? one is peak and what about second? Thanks a lot!!! $\endgroup$
    – user4947
    Jul 4, 2013 at 14:07
  • $\begingroup$ the second is the peak of the second signals' autocorrelation function, see my edit … $\endgroup$
    – Twonky
    Jul 4, 2013 at 20:38
  • $\begingroup$ Great!! thanks now is clear what you mean.If I'll have more questions I'll let you know. $\endgroup$
    – user4947
    Jul 5, 2013 at 14:33
  • 1
    $\begingroup$ Added two working examples. But correlation coefficient is not the best solution to find similar words in speech signals (speech recognition). To get reliable results you have to use more sophisticated methods, that are completely out of scope for a single answer. $\endgroup$
    – Twonky
    Jul 7, 2013 at 17:16

the autocorrelation of your sample should have a peak at t=0. the value of this peak should give you a good idea of a threshold value. The simplest apporoach to do keyword-searching in realtime data would be to divide incoming data into frames and keep cross correlating the required waveform against the frames and check whether the resultant has a peak higher than the estimated threshold ... However this is a rough method and suseptible to false peaks due to amplitude variations in incoming data

  • $\begingroup$ Hi thanks for answer, but when I use correlation coefficient I don't get value in 0-1 interval. As I think I do something wrong, I calculate correlation coefficient in ffts, is it right or not? $\endgroup$
    – user4947
    Jul 4, 2013 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.