Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group Delay Calculation Does not Unwrap Phase #149

Open
roseengineering opened this issue May 23, 2021 · 0 comments
Open

Group Delay Calculation Does not Unwrap Phase #149

roseengineering opened this issue May 23, 2021 · 0 comments

Comments

@roseengineering
Copy link

roseengineering commented May 23, 2021

NanoVNA/plot.c

Line 449 in d02db79

return atan2f(r, i) / (2 * VNA_PI * deltaf);

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant