pull/110/head
Holger Mueller 2019-11-25 11:00:30 +01:00
rodzic 8e446dcfb6
commit 5cc454da14
2 zmienionych plików z 5 dodań i 10 usunięć

Wyświetl plik

@ -21,27 +21,21 @@ from typing import List, NamedTuple
from NanoVNASaver.SITools import Value, Format from NanoVNASaver.SITools import Value, Format
def clamp_value(value: Real, rmin: Real, rmax: Real) -> Real:
assert rmin <= rmax
if value < rmin:
return rmin
if value > rmax:
return rmax
return value
def norm_to_impedance(z: complex, ref_impedance: float = 50) -> complex: def norm_to_impedance(z: complex, ref_impedance: float = 50) -> complex:
"""Calculate impedance from normalized z""" """Calculate impedance from normalized z"""
return z * ref_impedance return z * ref_impedance
def reflection_coefficient(z: complex, ref_impedance: float = 50) -> complex: def reflection_coefficient(z: complex, ref_impedance: float = 50) -> complex:
"""Calculate reflection coefficient for z""" """Calculate reflection coefficient for z"""
return (z - ref_impedance) / (z + ref_impedance) return (z - ref_impedance) / (z + ref_impedance)
def gamma_to_impedance(gamma: complex, ref_impedance: float = 50) -> complex: def gamma_to_impedance(gamma: complex, ref_impedance: float = 50) -> complex:
"""Calculate reflection coefficient for z""" """Calculate reflection coefficient for z"""
return ((-gamma - 1) / (gamma - 1)) * ref_impedance return ((-gamma - 1) / (gamma - 1)) * ref_impedance
class Datapoint(NamedTuple): class Datapoint(NamedTuple):
freq: int freq: int
re: float re: float
@ -98,6 +92,7 @@ class Datapoint(NamedTuple):
return 0 return 0
return imp.imag * 1 / (self.freq * 2 * math.pi) return imp.imag * 1 / (self.freq * 2 * math.pi)
def clamp_value(value: Real, rmin: Real, rmax: Real) -> Real: def clamp_value(value: Real, rmin: Real, rmax: Real) -> Real:
assert rmin <= rmax assert rmin <= rmax
if value < rmin: if value < rmin: