diff --git a/NanoVNASaver/Formatting.py b/NanoVNASaver/Formatting.py index b0d11f7..2f04972 100644 --- a/NanoVNASaver/Formatting.py +++ b/NanoVNASaver/Formatting.py @@ -36,6 +36,7 @@ FMT_REACT = SITools.Format(max_nr_digits=5, space_str=" ", allow_strip=True) FMT_COMPLEX = SITools.Format(max_nr_digits=3, allow_strip=True, printable_min=0, unprintable_under="- ") FMT_COMPLEX_NEG = SITools.Format(max_nr_digits=3, allow_strip=True) +FMT_WAVELENGTH = SITools.Format(max_nr_digits=4, space_str=" ") FMT_PARSE = SITools.Format(parse_sloppy_unit=True, parse_sloppy_kilo=True, parse_clamp_min=0) @@ -114,6 +115,9 @@ def format_complex_imp(z: complex, allow_negative: bool = False) -> str: im = SITools.Value(abs(z.imag), fmt=FMT_COMPLEX) return f"{re}{'-' if z.imag < 0 else '+'}j{im} \N{OHM SIGN}" +def format_wavelength(length: Number) -> str: + return str(SITools.Value(length, "m", FMT_WAVELENGTH)) + def parse_frequency(freq: str) -> int: try: diff --git a/NanoVNASaver/Marker/Delta.py b/NanoVNASaver/Marker/Delta.py index e13b1b7..7488ea9 100644 --- a/NanoVNASaver/Marker/Delta.py +++ b/NanoVNASaver/Marker/Delta.py @@ -31,6 +31,7 @@ from NanoVNASaver.Formatting import ( format_q_factor, format_resistance, format_vswr, + format_wavelength, ) from .Widget import Marker @@ -87,6 +88,8 @@ class DeltaMarker(Marker): self.label['actualfreq'].setText( format_frequency_space(s11_b.freq - s11_a.freq)) + self.label['lambda'].setText( + format_wavelength(s11_b.wavelength - s11_a.wavelength)) self.label['admittance'].setText(format_complex_imp(imp_p, True)) self.label['impedance'].setText(format_complex_imp(imp, True)) diff --git a/NanoVNASaver/Marker/Values.py b/NanoVNASaver/Marker/Values.py index ec72931..0cf4e70 100644 --- a/NanoVNASaver/Marker/Values.py +++ b/NanoVNASaver/Marker/Values.py @@ -30,6 +30,7 @@ class Label(NamedTuple): TYPES = ( Label("actualfreq", "Frequency", "Actual frequency", True), + Label("lambda", "Wavelength", "Wavelength", False), Label("impedance", "Impedance", "Impedance", True), Label("admittance", "Admittance", "Admittance", False), Label("serr", "Series R", "Series R", False), diff --git a/NanoVNASaver/Marker/Widget.py b/NanoVNASaver/Marker/Widget.py index ae88139..10cddc8 100644 --- a/NanoVNASaver/Marker/Widget.py +++ b/NanoVNASaver/Marker/Widget.py @@ -35,6 +35,7 @@ from NanoVNASaver.Formatting import ( format_q_factor, format_resistance, format_vswr, + format_wavelength, parse_frequency, ) from NanoVNASaver.Inputs import MarkerFrequencyInputWidget as FrequencyInput @@ -317,6 +318,7 @@ class Marker(QtCore.QObject, Value): x_p_str = ind_p_str self.label['actualfreq'].setText(format_frequency_space(s11.freq)) + self.label['lambda'].setText(format_wavelength(s11.wavelength)) self.label['admittance'].setText(format_complex_imp(imp_p)) self.label['impedance'].setText(format_complex_imp(imp)) self.label['parc'].setText(cap_p_str) diff --git a/NanoVNASaver/RFTools.py b/NanoVNASaver/RFTools.py index 160f85e..2eb1151 100644 --- a/NanoVNASaver/RFTools.py +++ b/NanoVNASaver/RFTools.py @@ -55,6 +55,10 @@ class Datapoint(NamedTuple): return 1 return (1 + mag) / (1 - mag) + @property + def wavelength(self) -> float: + return 299792458 / self.freq + def impedance(self, ref_impedance: float = 50) -> complex: return gamma_to_impedance(self.z, ref_impedance)