diff --git a/NanoVNASaver/Chart.py b/NanoVNASaver/Chart.py index 0e45b5a..34213bf 100644 --- a/NanoVNASaver/Chart.py +++ b/NanoVNASaver/Chart.py @@ -1057,13 +1057,8 @@ class LogMagChart(FrequencyChart): @staticmethod def logMag(p: Datapoint) -> float: - re = p.re - im = p.im - re50 = 50 * (1 - re * re - im * im) / (1 + re * re + im * im - 2 * re) - im50 = 50 * (2 * im) / (1 + re * re + im * im - 2 * re) - # Calculate the reflection coefficient - mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt((re50 + 50) * (re50 + 50) + im50 * im50) - return -20 * math.log10(mag) + from NanoVNASaver.NanoVNASaver import NanoVNASaver + return NanoVNASaver.gain(p) class QualityFactorChart(FrequencyChart): diff --git a/NanoVNASaver/Marker.py b/NanoVNASaver/Marker.py index 68d1dc2..9697fe6 100644 --- a/NanoVNASaver/Marker.py +++ b/NanoVNASaver/Marker.py @@ -85,7 +85,6 @@ class Marker(QtCore.QObject): line = QtWidgets.QFrame() line.setFrameShape(QtWidgets.QFrame.VLine) - #line.setFrameShadow(QtWidgets.QFrame.Sunken) left_form = QtWidgets.QFormLayout() right_form = QtWidgets.QFormLayout() @@ -169,12 +168,24 @@ class Marker(QtCore.QObject): from NanoVNASaver.NanoVNASaver import NanoVNASaver if self.location != -1: im50, re50, vswr = NanoVNASaver.vswr(s11data[self.location]) - rp = (re50 ** 2 + im50 ** 2) / re50 - xp = (re50 ** 2 + im50 ** 2) / im50 - re50 = round(re50, 4 - max(0, math.floor(math.log10(abs(re50))))) - rp = round(rp, 4 - max(0, math.floor(math.log10(abs(rp))))) - im50 = round(im50, 4 - max(0, math.floor(math.log10(abs(im50))))) - xp = round(xp, 4 - max(0, math.floor(math.log10(abs(xp))))) + if re50 > 0: + rp = (re50 ** 2 + im50 ** 2) / re50 + rp = round(rp, 4 - max(0, math.floor(math.log10(abs(rp))))) + + re50 = round(re50, 4 - max(0, math.floor(math.log10(abs(re50))))) + else: + rp = 0 + re50 = 0 + + if im50 > 0: + xp = (re50 ** 2 + im50 ** 2) / im50 + xp = round(xp, 4 - max(0, math.floor(math.log10(abs(xp))))) + else: + xp = 0 + + if im50 != 0: + im50 = round(im50, 4 - max(0, math.floor(math.log10(abs(im50))))) + if im50 < 0: im50str = " -j" + str(-1 * im50) else: @@ -190,7 +201,6 @@ class Marker(QtCore.QObject): self.impedance_label.setText(str(re50) + im50str) self.parallel_r_label.setText(str(rp) + " \N{OHM SIGN}") self.parallel_x_label.setText(xpstr) - #self.returnloss_label.setText(str(round(20 * math.log10((vswr - 1) / (vswr + 1)), 3)) + " dB") self.returnloss_label.setText(str(round(NanoVNASaver.gain(s11data[self.location]), 3)) + " dB") capacitance = NanoVNASaver.capacitanceEquivalent(im50, s11data[self.location].freq) inductance = NanoVNASaver.inductanceEquivalent(im50, s11data[self.location].freq) @@ -200,7 +210,12 @@ class Marker(QtCore.QObject): if vswr < 0: vswr = "-" self.vswr_label.setText(str(vswr)) - self.quality_factor_label.setText(str(round(NanoVNASaver.qualifyFactor(s11data[self.location]), 1))) + q = NanoVNASaver.qualifyFactor(s11data[self.location]) + if q > 10000 or q < 0: + q_str = "\N{INFINITY}" + else: + q_str = str(round(q, 1)) + self.quality_factor_label.setText(q_str) self.s11_phase_label.setText( str(round(PhaseChart.angle(s11data[self.location]), 2)) + "\N{DEGREE SIGN}") if len(s21data) == len(s11data): diff --git a/NanoVNASaver/NanoVNASaver.py b/NanoVNASaver/NanoVNASaver.py index e85d470..f3a80f0 100644 --- a/NanoVNASaver/NanoVNASaver.py +++ b/NanoVNASaver/NanoVNASaver.py @@ -795,10 +795,10 @@ class NanoVNASaver(QtWidgets.QWidget): def qualifyFactor(data: Datapoint): im50, re50, _ = NanoVNASaver.vswr(data) if re50 != 0: - Q = im50 / re50 + Q = abs(im50 / re50) else: - Q = 0 - return abs(Q) + Q = -1 + return Q @staticmethod def capacitanceEquivalent(im50, freq) -> str: @@ -818,7 +818,7 @@ class NanoVNASaver(QtWidgets.QWidget): def inductanceEquivalent(im50, freq) -> str: if freq == 0: return "- nH" - inductance = im50 * 1000000000/ (freq * 2 * math.pi) + inductance = im50 * 1000000000 / (freq * 2 * math.pi) if abs(inductance) > 10000: return str(round(inductance / 1000, 2)) + " μH" elif abs(inductance) > 1000: