Test for gamma of 1+0j
pull/161/head
Holger Mueller 2020-02-15 20:12:49 +01:00
rodzic 707bd792c7
commit cb1ef3608c
2 zmienionych plików z 5 dodań i 2 usunięć

Wyświetl plik

@ -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: def gamma_to_impedance(gamma: complex, ref_impedance: float = 50) -> complex:
"""Calculate impedance from gamma""" """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: def parseFrequency(freq: str) -> int:
@ -114,7 +117,6 @@ class Datapoint(NamedTuple):
return 20 * math.log10(mag) return 20 * math.log10(mag)
return -math.inf return -math.inf
@property @property
def vswr(self) -> float: def vswr(self) -> float:
mag = abs(self.z) mag = abs(self.z)

Wyświetl plik

@ -64,6 +64,7 @@ class TestRFTools(unittest.TestCase):
def test_gamma_to_impedance(self): def test_gamma_to_impedance(self):
self.assertEqual(gamma_to_impedance(0), 50) self.assertEqual(gamma_to_impedance(0), 50)
self.assertAlmostEqual(gamma_to_impedance(0.2), 75) self.assertAlmostEqual(gamma_to_impedance(0.2), 75)
self.assertEqual(gamma_to_impedance(1), math.inf)
# TODO: insert more test values here # TODO: insert more test values here
def test_clamp_value(self): def test_clamp_value(self):