# Phase difference between two wave files

I am doing comparison between two wave files, How to calculate phase difference between those files? Second wave is generated by making some changes in the first one .I have tried calculating phase like this:-

y, sr = librosa.load('first.wav')
D = librosa.stft(y)
magnitude, phase1 = librosa.magphase(D)

D1 = librosa.stft(y1)
magnitude1, phase2 = librosa.magphase(D1)


then calculated the difference as (phase1-phase2)

Is this the correct way??

• Are the two wave files somehow related? What have you tried so far? – dsp_user May 27 at 6:10
• @dsp_user yes second wave is generated by making some changes in the first one .I have tried calculating phase like this:-y, sr = librosa.load('sample.wav') D = librosa.stft(y) magnitude, phase = librosa.magphase(D) calculate phase and phase1 for both the files and than find out the difference.Is this the correct way?? – Saumya May 28 at 3:05
• you will have to provide more information to have your question reopened. – dsp_user May 28 at 6:57

You need to cross-correlate those two wavfiles : from wikipedia "cross-correlation is a measure of similarity of two series as a function of the displacement of one relative to the other"

The result obtained will give you a measure of the similarity between those two audio signals depending on the time.

Therefore you will need to find the time for which the cross-correlation is at its maximum (ie : maximum similarity), it will indicates you the time delay, phase between those two signals.