1
votes

I have two vectors that represent two different signals, each being a sine wave with the same frequency. I've tried cross-correlation, Fourier transforms, Hilbert transforms, etc, but nothing returns the correct, theoretical value (in radians) at a specific frequency (should be negative). Is there any method in Matlab to calculate the phase difference of two sine waves with the same frequency?

Note: I have access to the frequency and amplitudes of both signals, and I can post some code if needed.

1
All of these methods are plausible, depending on context/implementation. What specifically did you try, what result did you get, and what result did you expect?Oliver Charlesworth
@OliverCharlesworth I've tried using xcorr (cross-correlation), the fft function, and the hilbert function in an attempt to calculate the phase difference, but the values do not match up with the theoretical values at the same frequency. I expected values less (more negative) than what I had received. At low frequencies, the hilbert transform came closest, but it jets off at higher frequencies (300+ Hz) for some reason.Jacob G.
Can you post some minimal runnable example including sample data, because xcorr and fft should definitely work. (I'm not familiar with hilbert)m7913d

1 Answers

2
votes

Assuming s1 and s2 are your isofrequential sine waves you can evaluate the phase difference (absolute value in radians) between them as easily as acos( dot(a,b) / (norm(a)*norm(b)) ).

x = 0:.001:100;
omega = 2*pi*100;
phi = pi/6;
s1 = sin(omega*x);
s2 = sin(omega*x - phi);
phase_diff = acos( dot(s1,s2) / (norm(s1)*norm(s2)) );