# Phase shift between two signals

So I got some oscilloscope captures for a project I'm doing and I'd like to find a phase shift between them because I don't trust the scope calculation.

So I extracted data from a .csv file and loaded it into Matlab and now I'd like to find a phase shift using FFT (I think). Is there a way to do this even though the second signal, output, is not a perfect sinusoid? ## 2 Answers

Your waveforms appear to have a low enough noise level to use interpolation of FFT results for phase estimation. First do an fftshift (to rotate the data halfway around your FFT vector) so that the FFT result phase reference point is in the center of you original data (not at the discontinuity or edges of your waveform data). Then do the FFTs, and estimate the location of the frequency peak (if between FFT result bins by interpolation and/or successive approximation, or by knowledge of the exact frequency by other means if available), then interpolate the complex phase between bins, if needed. Then compare the two phase estimations between the two waveforms.

There are many different ways to extract phase shift, the simplest one I think is using normalized cross-correlation using instruction 'xcorr' and then finding the index where the maximum correlation is placed. Other technique as you mentioned is using FFT and spectrum multiplication and ifft(equals to correlation in time) and/or calculation of arctan(complex/real) of bins. Other methods like Hilbert transform is comprehensively detailed in below links:

https://stackoverflow.com/questions/27545171/identifying-phase-shift-between-signals

Best method to extract phase shift between 2 sinosoids, from data provided

• For some reason using xcorr did not work or I did not know how to use it. Anyways, I found a way using FFT: { fft_a = fft(ds.values(:,1)); % FFT of the first signal fft_b = fft(ds.values(:,2)); % FFT of the second signal [Ma,Ia] = max(abs(fft_a)) % Finding peak positions [Mb,Ib] = max(abs(fft_b)) % Finding peak positions ph = angle(fft_b(Ib))-angle(fft_a(Ia)) ph = ph*180/pi; % phase in degrees } – MarkoP Aug 8 '16 at 8:31
• Well I don't know how to format a code but it's there so is someone can reformat it for me it'd be great. – MarkoP Aug 8 '16 at 8:33
• @MarkoP, well done, that's right. – MimSaad Aug 8 '16 at 12:22