I have been working on a problem where I am given two songs which are of the same category but there is a time difference between them. Eg. one song starts at x sec and other song starts at y sec. So my task is to find the x and y.
The length of the two songs can vary but the content of the two songs will remain the same.

Currently I am using cross-correlation using FFT for finding the offset between them but it is not giving me correct results.

For making the length of signals same I am zero padding the signal which is shorter in length.

Can someone guide me what I am doing wrong in this problem ?

I really appreciate your responses. Thanks


Thanks guys for replying.. I am doing in Python and using below algorithm for finding the offset:
1. Using librosa.load function to get the audio signals of both the songs.
2. Then I zero pad the shorter signal from last and make sure it is power of 2.
3. Find the FFT of the two signals using scipy library function of python.(spipy.fftpack.fft)
4. Once I get the fft , I take the cojugate of one of the signals.
5. Elementwise multiplication of the two fft signals
6. Doing ifft of the numpy array of the output signals after multiplication.
7. Finding the peak index of that array.

P.S. The song length can be around 5-6 mins so I am sampling at the rate of 44.1Khz . So you can expect very large sample space. Also , the bitrate of the two songs can be different.(I am not sure that will effect it or not)

Any idea if I am doing wrong?


  • $\begingroup$ Can you be more specific? What did you get and why do you think it's wrong? Perhaps show some code. BTW, you know you can only find (x-y) and not x and y, right? $\endgroup$
    – ThP
    Jun 20, 2015 at 6:11
  • $\begingroup$ Just go for some more sophisticated algorithm instead of using the x-correlation, i.e. MATCH $\endgroup$
    – jojeck
    Jun 20, 2015 at 11:18
  • $\begingroup$ I tried using FastDTW for my problem too but it is inefficient for large sample size of around 1 Million time series. $\endgroup$
    – homer
    Jun 22, 2015 at 7:50

1 Answer 1


First of all, apply a normalized cross correlation, which is more robust to certain variations. MATLAB's xcorr function has an option to do that. Next, apply it in a sliding window fashion, where you apply the correlation as a running filter. Then, simply select the maximum peak.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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