How to calculate phase difference between 2 periodic signals recorded from oscilloscope?
2 views (last 30 days)
Show older comments
Varun Lokesh
on 21 Dec 2021
Commented: Star Strider
on 1 Feb 2022
I have recorded 2 signals from oscilloscope and stored it in a csv file.
I have ploted both the signals. But i need to calculate the phase difference between these 2 waves.
I have attached the csv file. consider the Channel 1 and 2.
I have plotted the code as below:
v=csvread("data.csv",2,0);
a=v(:,5); % the column you want to plot
a1=v(:,6);
ts=2e-9; % the sampling time is available in data (excel file)
z=length(a);
t=0:ts:ts*z-ts;
subplot(2,1,1)
plot(t,a)
xlim([0 5e-7])
subplot(2,1,2)
plot(t,a1)
xlim([0 5e-7])
0 Comments
Accepted Answer
Star Strider
on 21 Dec 2021
One approach —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/840620/data.CSV', 'VariableNamingRule','preserve')
% C1 = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/840620/data.CSV')
time = T1.Var4(3:end,:);
CH1 = T1.Var5(3:end,:);
CH2 = T1.Var6(3:end,:);
Ts = mean(diff(time)) % Sampling Interval
Tsdc = Ts/std(diff(time)) % Check Regularity Of Sample Times
Fs = 1/Ts % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(time) % Signals Length
[CH1a,CH2a,Dly] = alignsignals(CH1, CH2); % Align Signals, Determine Delay
fprintf('Delay = %3d Samples',Dly)
[pks, locs] = findpeaks(CH1, 'MinPeakDistance',abs(Dly)*0.75); % Peaks & Locations (Indices)
FreqCH1 = 1/mean(diff(time(locs)))
PhaseDiffSec = Dly*Ts % Samples * Seconds/Sample
PhaseDiffCyc = PhaseDiffSec * FreqCH1 % Seconds * Cycles/Second
PhaseDiffRad = PhaseDiffSec * 2*pi*FreqCH1 % Seconds * Radians/Second
figure
plot(time, CH1)
hold on
plot(time, CH2)
plot(time(locs), CH1(locs), '+r')
hold off
grid
xlim([[-1 1]*0.1E-5+1.2E-5])
xlabel('Time')
ylabel('Amplitude')
title('Original Signals With Located Peaks')
S1 = 0.5*sign(sin(2*pi*time*FreqCH1)) + 0.5;
S2 = sign(sin(2*pi*time*FreqCH1 - PhaseDiffRad)) + 1.1;
figure
plot(time, S1)
hold on
plot(time, S2)
hold off
grid
xlim([[-1 1]*0.1E-5+1.2E-5])
ylim([-0.1 2]*1.1)
xlabel('Time')
ylabel('Amplitude')
title('Approximate Signlal Simulation To Check Results')
.
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
