How to determine the phase difference/phase shift between two signals?
233 views (last 30 days)
Show older comments
I have two sine signals(recorded with a detector). One on Channel A and other on Channel B. I need help with determining the phase shift between these two using the function: y = y0 + A*sin(2*pi*0.03*x + b) , Where b gives the phase of signal, A-amplitude & y0 offset. I have attached .csv file for reference data. I was able to fit them and detemine the phase b for each separately using the curve fitting toolbox but, I am struggling to do them simultaneously for more than 1 file.
0 Comments
Answers (1)
Star Strider
on 10 Jan 2019
Edited: Star Strider
on 12 Jan 2019
Here is something to experiment with (based on the Arbitrary Phase Shift (link) section of the Wikipedia article List of trigonometric identities):
EDIT — (12 Jan 2019 at 03:45 UCT)
Added equations (copied from the Wikipedia article).
D = csvread('sine signals.csv', 2, 0);
t = D(:,1);
C1 = D(:,2);
C2 = D(:,3);
C1s = [mean(C1); 2*std(C1)];
C2s = [mean(C2); 2*std(C2)];
sinsum = C1 + C2;
sinsums = [mean(sinsum); 2*std(sinsum)];
c_fcn = @(theta) sqrt(C1s(2).^2 + C2s(2).^2 + 2*C1s(2).*C2s(2).*cos(theta)) - sinsums(2);
theta = fzero(c_fcn, 1);
thetadeg = theta*180/pi;
phi_fcn = @(theta) atan2(C2s(2).*sin(theta), C1s(2) + C2s(2).*cos(theta));
phi = fminsearch(@(b)norm(phi_fcn(b)), 1);
figure
plot(t, C1, t, C2, t, sinsum)
grid
legend('Ch 1', 'Ch 2', 'Ch 1 + Ch 2', 'Location','best')
text(250, 2, sprintf('\\theta = %.3f rad = %.3f\\circ', theta, thetadeg))
Note that θ is the phase difference between the two waveforms, and ϕ is the phase of the resulting waveform sum. (The θ value looks correct, since the two waveforms appear to be nearly 180° out-of-phase with each other.) I did not do a regression to find the phases (although that is an option: Curve fitting to a sinusoidal function) so experiment with this to see if it gives you essentially the same information.
1 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!