From: Abraham Pollayil Alexander on
I used correlation (Multiply and Integrate) technique to find the phase difference between the two signals. The principle is when two signals are in phase their correlation is maximum when compared with the correlation between them when there is phase difference between them. So, Find the correlation between the arrays(say A1*A2') and shift any one array and find the correlation again till u get maximum correlation. The no: of shifts till u get the max correlation will be proportional to the phase difference. the angle can be obtained by using the formula
Phase Difference (in Degrees) = N * (360/(fs/fd)),
where N is the number of shifts to reach the max correlation.
fs is the sampling frequency,
fd is the frequency of the signals (supposing both signal are having the same fundamental frequency).

For this, I found the correlation with every shifts(circular) for the full array. I stored the correlation values in another array, and found out the number of samples to reach the first maximum by iterating through the correlation array values(in which previous_value<current_value>next_value).