# Calculate phase shift between two signals

Consider the measurements of two modulated AC signals (voltage and current) which may have noise, harmonics and a DC bias. Each measured signal consists of a list for the time and a list for the corresponding values.

My goal is to find out the phase shift in degrees between these two signals in a robust way.

I would like to realize this in the frequency domain perhaps by calculating and evaluating the fundamental waves of the signals.

Any help or sample code (MATLAB) would be very much appreciated.

• By "phase shift" do you really mean "time shift"? – Jim Clay Sep 13 '13 at 18:21
• I mean the phase shifting between current and voltage. E.g.: In the case of a capacitor, the current leads the voltage by 90 degrees. I want to calculate that 90 degrees. – lR8n6i Sep 14 '13 at 11:56
• correct. filtering does nothing for the accuracy. accuracy is improved by using a longer fft, not filtering. – Jerry Oct 2 '13 at 23:42

Do this procedure on both signals, and subtract the results to get what you want (it would be a nearly constant sequence whose value is phase shift in radians)

1. Perform FFT on the signal to obtain its spectrum.

2. Find the dominant harmonic of the signal : $f_c$ (where the peak of FFT occurs).

3. Filter the signal with a narrow-band linear phase filter (center = $f_c$, bandwidth as less as possible).

4. Again, perform FFT on the signal and extract its phase.

Note : It is assumed that the signal has a dominant frequency otherwise a phase shift is pointless

• Hi! Thank you for your response. I could accomplish 1 and 2. Could you maybe recommend a suitable filter type for task 3? Do you think a linear phase filter should be used? – lR8n6i Sep 13 '13 at 14:40
• My knowledge is not enough to recommend you a suitable filter type. You can try most important ones, and choose one that works well. Yes the filter must be a linear, otherwise it will distort the phase of the inputs. – Mahdi Khosravi Sep 13 '13 at 16:05
• Why don't you just read the phases from the FFT bins? What's the filter for? – endolith Sep 14 '13 at 3:40
• @endolith the filter is arbitrary and its usage depends on the level of the noise. – Mahdi Khosravi Sep 14 '13 at 6:12
• @MahdiKhosravi: but what does it do? what is its purpose? the peak bin will be the same before and after the filter – endolith Sep 14 '13 at 13:23