Skip to content

Commit

Permalink
Merge pull request #451 from NanoVNA-Saver/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
zarath authored Jan 4, 2022
2 parents 43fd3b7 + fdb8f0a commit 7007812
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion NanoVNASaver/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

VERSION = "0.3.10-pre07"
VERSION = "0.3.10-pre08"
VERSION_URL = (
"https://raw.githubusercontent.com/"
"NanoVNA-Saver/nanovna-saver/master/NanoVNASaver/About.py")
Expand Down
26 changes: 12 additions & 14 deletions NanoVNASaver/Calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions NanoVNASaver/Formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion NanoVNASaver/Marker/Delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion NanoVNASaver/Marker/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions NanoVNASaver/Windows/CalibrationSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 7007812

Please sign in to comment.