diff --git a/NanoVNASaver/RFTools.py b/NanoVNASaver/RFTools.py index cf22b07..f0bf539 100644 --- a/NanoVNASaver/RFTools.py +++ b/NanoVNASaver/RFTools.py @@ -82,7 +82,10 @@ def reflection_coefficient(z: complex, ref_impedance: float = 50) -> complex: def gamma_to_impedance(gamma: complex, ref_impedance: float = 50) -> complex: """Calculate impedance from gamma""" - return ((-gamma - 1) / (gamma - 1)) * ref_impedance + try: + return ((-gamma - 1) / (gamma - 1)) * ref_impedance + except ZeroDivisionError: + return math.inf def parseFrequency(freq: str) -> int: @@ -114,7 +117,6 @@ class Datapoint(NamedTuple): return 20 * math.log10(mag) return -math.inf - @property def vswr(self) -> float: mag = abs(self.z) diff --git a/test/test_rftools.py b/test/test_rftools.py index 68f90f9..0722386 100644 --- a/test/test_rftools.py +++ b/test/test_rftools.py @@ -64,6 +64,7 @@ class TestRFTools(unittest.TestCase): def test_gamma_to_impedance(self): self.assertEqual(gamma_to_impedance(0), 50) self.assertAlmostEqual(gamma_to_impedance(0.2), 75) + self.assertEqual(gamma_to_impedance(1), math.inf) # TODO: insert more test values here def test_clamp_value(self):