From 4bee354bf70da475d48e0b4a40f8db2ee0aea535 Mon Sep 17 00:00:00 2001 From: Roel Jordans Date: Tue, 14 Dec 2021 11:37:10 +0100 Subject: [PATCH 1/3] Change calculation of admittance value and unit in marker plotting code Signed-off-by: Roel Jordans --- NanoVNASaver/Formatting.py | 12 ++++++++++++ NanoVNASaver/Marker/Delta.py | 3 ++- NanoVNASaver/Marker/Widget.py | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/NanoVNASaver/Formatting.py b/NanoVNASaver/Formatting.py index 449a53ea..17b4a9cc 100644 --- a/NanoVNASaver/Formatting.py +++ b/NanoVNASaver/Formatting.py @@ -110,6 +110,18 @@ def format_phase(val: float) -> str: return f"{math.degrees(val):.2f}""\N{DEGREE SIGN}" +def format_complex_adm(z: complex, allow_negative: bool = False) -> str: + if z == 0: + return "- S" + adm = 1/z + + fmt_re = FMT_COMPLEX + if allow_negative: + fmt_re = FMT_COMPLEX_NEG + re = SITools.Value(adm.real, fmt=fmt_re) + im = SITools.Value(abs(adm.imag), fmt=FMT_COMPLEX) + return f"{re}{'-' if adm.imag < 0 else '+'}j{im} S" + def format_complex_imp(z: complex, allow_negative: bool = False) -> str: fmt_re = FMT_COMPLEX if allow_negative: diff --git a/NanoVNASaver/Marker/Delta.py b/NanoVNASaver/Marker/Delta.py index 73d3fcc8..1f068768 100644 --- a/NanoVNASaver/Marker/Delta.py +++ b/NanoVNASaver/Marker/Delta.py @@ -21,6 +21,7 @@ from NanoVNASaver import RFTools from NanoVNASaver.Formatting import ( format_capacitance, + format_complex_adm, format_complex_imp, format_frequency_space, format_gain, @@ -90,7 +91,7 @@ def updateLabels(self): # pylint: disable=arguments-differ 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['admittance'].setText(format_complex_adm(imp_p, True)) self.label['impedance'].setText(format_complex_imp(imp, True)) self.label['parc'].setText(cap_p_str) diff --git a/NanoVNASaver/Marker/Widget.py b/NanoVNASaver/Marker/Widget.py index 76c07216..cf19aa19 100644 --- a/NanoVNASaver/Marker/Widget.py +++ b/NanoVNASaver/Marker/Widget.py @@ -25,6 +25,7 @@ from NanoVNASaver import RFTools from NanoVNASaver.Formatting import ( format_capacitance, + format_complex_adm, format_complex_imp, format_frequency_space, format_gain, @@ -328,7 +329,7 @@ def updateLabels(self, 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['admittance'].setText(format_complex_adm(imp)) self.label['impedance'].setText(format_complex_imp(imp)) self.label['parc'].setText(cap_p_str) self.label['parl'].setText(ind_p_str) From d03982af7353d076d10979debc30bd09daa66df6 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Mon, 3 Jan 2022 19:42:17 +0300 Subject: [PATCH 2/3] Fix division on zero in Open calibration standard C0 value = 0 Implement Load C calibration use --- NanoVNASaver/Calibration.py | 26 ++++++++++----------- NanoVNASaver/Windows/CalibrationSettings.py | 20 +++++++--------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/NanoVNASaver/Calibration.py b/NanoVNASaver/Calibration.py index 56c385b8..c9e88ad8 100644 --- a/NanoVNASaver/Calibration.py +++ b/NanoVNASaver/Calibration.py @@ -235,38 +235,36 @@ def gamma_short(self, freq: int) -> complex: g = Calibration.IDEAL_SHORT if not self.useIdealShort: logger.debug("Using short calibration set values.") - Zsp = complex(0, 1) * 2 * math.pi * freq * ( + Zsp = complex(0, 2 * math.pi * freq * ( self.shortL0 + self.shortL1 * freq + - self.shortL2 * freq**2 + self.shortL3 * freq**3) + self.shortL2 * freq**2 + self.shortL3 * freq**3)) # Referencing https://arxiv.org/pdf/1606.02446.pdf (18) - (21) g = (Zsp / 50 - 1) / (Zsp / 50 + 1) * cmath.exp( - complex(0, 1) * 2 * math.pi * 2 * freq * - self.shortLength * -1) + complex(0, 2 * math.pi * 2 * freq * self.shortLength * -1)) return g def gamma_open(self, freq: int) -> complex: g = Calibration.IDEAL_OPEN if not self.useIdealOpen: logger.debug("Using open calibration set values.") - divisor = (2 * math.pi * freq * ( + Zop = complex(0, 2 * math.pi * freq * ( self.openC0 + self.openC1 * freq + self.openC2 * freq**2 + self.openC3 * freq**3)) - if divisor != 0: - Zop = complex(0, -1) / divisor - g = ((Zop / 50 - 1) / (Zop / 50 + 1)) * cmath.exp( - complex(0, 1) * 2 * math.pi * - 2 * freq * self.openLength * -1) + g = ((1 - 50 * Zop) / (1 + 50 * Zop)) * cmath.exp( + complex(0, 2 * math.pi * 2 * freq * self.openLength * -1)) return g def gamma_load(self, freq: int) -> complex: g = Calibration.IDEAL_LOAD if not self.useIdealLoad: logger.debug("Using load calibration set values.") - Zl = self.loadR + (complex(0, 1) * 2 * - math.pi * freq * self.loadL) + Zl = complex(self.loadR, 0) + if self.loadC > 0: + Zl = self.loadR / complex(1, 2 * self.loadR * math.pi * freq * self.loadC) + if self.loadL > 0: + Zl = Zl + complex(0, 2 * math.pi * freq * self.loadL) g = (Zl / 50 - 1) / (Zl / 50 + 1) * cmath.exp( - complex(0, 1) * 2 * math.pi * - 2 * freq * self.loadLength * -1) + complex(0, 2 * math.pi * 2 * freq * self.loadLength * -1)) return g def gamma_through(self, freq: int) -> complex: diff --git a/NanoVNASaver/Windows/CalibrationSettings.py b/NanoVNASaver/Windows/CalibrationSettings.py index 66018461..f990cb73 100644 --- a/NanoVNASaver/Windows/CalibrationSettings.py +++ b/NanoVNASaver/Windows/CalibrationSettings.py @@ -185,14 +185,14 @@ def __init__(self, app: QtWidgets.QWidget): self.load_resistance.setMinimumHeight(20) self.load_inductance = QtWidgets.QLineEdit("0") self.load_inductance.setMinimumHeight(20) - # self.load_capacitance = QtWidgets.QLineEdit("0") - # self.load_capacitance.setMinimumHeight(20) - # self.load_capacitance.setDisabled(True) # Not yet implemented + self.load_capacitance = QtWidgets.QLineEdit("0") + self.load_capacitance.setMinimumHeight(20) + #self.load_capacitance.setDisabled(True) # Not yet implemented self.load_length = QtWidgets.QLineEdit("0") self.load_length.setMinimumHeight(20) cal_load_form.addRow("Resistance (\N{OHM SIGN})", self.load_resistance) cal_load_form.addRow("Inductance (H(e-12))", self.load_inductance) - # cal_load_form.addRow("Capacitance (F(e-12))", self.load_capacitance) + cal_load_form.addRow("Capacitance (F(e-15))", self.load_capacitance) cal_load_form.addRow("Offset Delay (ps)", self.load_length) self.cal_through_box = QtWidgets.QGroupBox("Through") @@ -313,7 +313,7 @@ def saveCalibrationStandard(self): self.app.settings.setValue("LoadR", self.load_resistance.text()) self.app.settings.setValue("LoadL", self.load_inductance.text()) - # self.app.settings.setValue("LoadC", self.load_capacitance.text()) + self.app.settings.setValue("LoadC", self.load_capacitance.text()) self.app.settings.setValue("LoadDelay", self.load_length.text()) self.app.settings.setValue("ThroughDelay", self.through_length.text()) @@ -348,7 +348,7 @@ def loadCalibrationStandard(self): self.load_resistance.setText(str(self.app.settings.value("LoadR", 50))) self.load_inductance.setText(str(self.app.settings.value("LoadL", 0))) - # self.load_capacitance.setText(str(self.app.settings.value("LoadC", 0))) + self.load_capacitance.setText(str(self.app.settings.value("LoadC", 0))) self.load_length.setText(str(self.app.settings.value("LoadDelay", 0))) self.through_length.setText(str(self.app.settings.value("ThroughDelay", 0))) @@ -511,8 +511,6 @@ def calculate(self): try: self.app.calibration.openC0 = self.getFloatValue( self.open_c0_input.text())/10**15 - if self.app.calibration.openC0 == 0: - raise ValueError("C0 cannot be 0.") self.app.calibration.openC1 = self.getFloatValue( self.open_c1_input.text())/10**27 self.app.calibration.openC2 = self.getFloatValue( @@ -531,9 +529,9 @@ def calculate(self): self.app.calibration.loadR = self.getFloatValue( self.load_resistance.text()) self.app.calibration.loadL = self.getFloatValue( - self.load_inductance.text())/10**12 - # self.app.calibration.loadC = self.getFloatValue( - # self.load_capacitance.text()) / 10 ** 12 + self.load_inductance.text()) / 10**12 + self.app.calibration.loadC = self.getFloatValue( + self.load_capacitance.text()) / 10 ** 15 self.app.calibration.loadLength = self.getFloatValue( self.load_length.text())/10**12 self.app.calibration.useIdealLoad = False From fdb8f0ac432a793a9cdca485c2900377cf11ff73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20M=C3=BCller?= Date: Tue, 4 Jan 2022 08:13:49 +0100 Subject: [PATCH 3/3] prepare merge to testing --- NanoVNASaver/About.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NanoVNASaver/About.py b/NanoVNASaver/About.py index 0cdb1106..b0b800aa 100644 --- a/NanoVNASaver/About.py +++ b/NanoVNASaver/About.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -VERSION = "0.3.10-pre07" +VERSION = "0.3.10-pre08" VERSION_URL = ( "https://raw.githubusercontent.com/" "NanoVNA-Saver/nanovna-saver/master/NanoVNASaver/About.py")