kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
rodzic
707bd792c7
commit
cb1ef3608c
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Ładowanie…
Reference in New Issue