When writing this Digilent Analog Discovery 2 does not have built-in phase angle measurement function, however there is custom script provided:
var sum1 = 0
var sum2 = 0
var sum12 = 0
var d1 = Scope.Channel1.visibledata
var d2 = Scope.Channel2.visibledata
for(var i = 0; i < d1.length; i++){
sum1 += d1[i]*d1[i]
sum2 += d2[i]*d2[i]
sum12 += d1[i]*d2[i]
}
sum1 /= d1.length
sum2 /= d1.length
sum12 /= d1.length
acos(sum12/sqrt(sum1*sum2))*180/PI
Script is based on integration and is principally functional, but due to various technical nuances often does not work or displays wrong value, as demonstrated on screenshot above - measurement "Phase" is ~5° off and unsigned, so in total 95°off. In general it can be considered working only for pure sinusoids, which is often not the case in real world, also need to manually determine if there is advance or lag. Substantially improved result can be obtained when using zero-crossing detection instead, with some additional code to account for phase sign. Full range is +-180°
// Phase angle measurement for WaveForms v0.6
// Zero crossing detection based, any wfm shape ok, +-180°
// By lab!fyi <info@lab.fyi>
// http://lab.fyi/oscilloscope_scripts/phase_shift_measurement/index.html
var channel_1 = Scope.Channel1;
var channel_2 = Scope.Channel2;
var detect_sign = true; // false for harsh conditions, very small angles
var visible_data_only = false; // false to use full record
var sign_detection_window = 4; // +-samples around trigger
var a1 = (visible_data_only) ? channel_1.visibledata : channel_1.alldata;
var a2 = (visible_data_only) ? channel_2.visibledata : channel_2.alldata;
var zti = round
(
(visible_data_only)
? channel_1.VisibleIndexOfTime(0)
: channel_1.IndexOfTime(0)
);
var i;
var s = 1;
var p = 0;
if (detect_sign)
{
for (i = zti - sign_detection_window; i < zti + sign_detection_window + 1; i++)
{
if (sign(a1[i]) > sign(a2[i])) s += 1;
if (sign(a1[i]) < sign(a2[i])) s -= 1;
}
s = sign(s / (sign_detection_window * 2 + 1));
}
for (i = 0; i < a1.length; i++)
{
p += sign(a1[i]) * -sign(a2[i]);
}
p = s * (p + a1.length) * 90 / a1.length;
p;
In above example input was 1MHz, sine on Ch1, square on Ch2. Different amplitudes. Cursors show ~-44.3°, new script ~-45° and old script 50°. Note that when phase diff is over 180° it starts to diminsh again with both formulas and reaches 0° by 360°.
Tests were conducted on Analog Discovery 2 and WaveForms version 3.8.10 beta 64-bit Qt5.6.3 Windows 7.
Signal generator was Siglent SDG2122X.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.