# Cross-Correlation to find the similartity of songs

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?

thanks

• 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?
– ThP
Jun 20 '15 at 6:11
• Just go for some more sophisticated algorithm instead of using the x-correlation, i.e. MATCH
– jojek
Jun 20 '15 at 11:18
• I tried using FastDTW for my problem too but it is inefficient for large sample size of around 1 Million time series. Jun 22 '15 at 7:50