Group Delay Calculation Does not Unwrap Phase
roseengineering opened this issue · 0 comments
Line 449 in d02db79
To properly calculate the group delay, -dphi / (2 * pi * df), the phase must be "unwrapped". Otherwise for large phase shifts (<180 deg) across measurement points, the group delay calculation will be in error. For a non-dispersive DUT like a coaxial cable, high accuracy group delay measurements require such a large frequency "aperture". A df of .3 / delay is recommended. Unfortunately because of this issue my measurements were wrong.
See https://twitter.com/gmagiros/status/1396204275089477636?s=20
This issue also exists in the nanovnav2 and nanovna-saver code.
The python code below demonstrates two ways to properly calculate group delay.
My method:
for n in range(1, len(ph)):
dphi = ph[n] - ph[n-1]
if dphi <= -np.pi: dphi += 2 * np.pi
if dphi >= np.pi: dphi -= 2 * np.pi
df = f[n] - f[n-1]
g[n][0] = -dphi / (2 * np.pi * df)
Or using the scikit-rf method:
for n in range(1, len(ph)):
while ph[n] - ph[n-1] < -np.pi: ph[n] += 2 * np.pi
while ph[n] - ph[n-1] >= np.pi: ph[n] -= 2 * np.pi
for n in range(0, len(ph)):
n1 = max(n - 1, 0)
n2 = min(n + 1, len(ph) - 1)
dphi = ph[n2] - ph[n1]
df = f[n2] - f[n1]
g[n][0] = -dphi / (df * 2 * np.pi)