diff --git a/NanoVNASaver/Analysis.py b/NanoVNASaver/Analysis.py index 10816f0..57e045c 100644 --- a/NanoVNASaver/Analysis.py +++ b/NanoVNASaver/Analysis.py @@ -1030,10 +1030,7 @@ class SimplePeakSearchAnalysis(Analysis): suffix = "" data = [] for d in self.app.data: - vswr = RFTools.calculateVSWR(d) - if vswr < 1: - vswr = float('inf') - data.append(vswr) + data.append(d.as_vswr()) elif self.rbtn_data_resistance.isChecked(): suffix = " \N{OHM SIGN}" data = [] @@ -1137,7 +1134,7 @@ class PeakSearchAnalysis(Analysis): if self.rbtn_data_vswr.isChecked(): data = [] for d in self.app.data: - data.append(RFTools.calculateVSWR(d)) + data.append(d.as_vswr()) elif self.rbtn_data_s21_gain.isChecked(): data = [] for d in self.app.data21: @@ -1228,10 +1225,7 @@ class VSWRAnalysis(Analysis): max_dips_shown = 3 data = [] for d in self.app.data: - vswr = RFTools.calculateVSWR(d) - if vswr < 1: - vswr = float('inf') - data.append(vswr) + data.append(d.as_vswr()) # min_idx = np.argmin(data) # # logger.debug("Minimum at %d", min_idx) diff --git a/NanoVNASaver/Chart.py b/NanoVNASaver/Chart.py index c3a83a7..8dbe6a8 100644 --- a/NanoVNASaver/Chart.py +++ b/NanoVNASaver/Chart.py @@ -1054,7 +1054,7 @@ class VSWRChart(FrequencyChart): minVSWR = 1 maxVSWR = 3 for d in self.data: - vswr = RFTools.calculateVSWR(d) + vswr = d.as_vswr() if vswr > maxVSWR: maxVSWR = vswr maxVSWR = min(self.maxDisplayValue, math.ceil(maxVSWR)) @@ -1136,8 +1136,7 @@ class VSWRChart(FrequencyChart): return self.topMargin + round((self.maxVSWR - vswr) / self.span * self.chartHeight) def getYPosition(self, d: Datapoint) -> int: - vswr = RFTools.calculateVSWR(d) - return self.getYPositionFromValue(vswr) + return self.getYPositionFromValue(d.as_vswr()) def valueAtPosition(self, y) -> List[float]: absy = y - self.topMargin diff --git a/NanoVNASaver/Marker.py b/NanoVNASaver/Marker.py index ef79e6d..db3e773 100644 --- a/NanoVNASaver/Marker.py +++ b/NanoVNASaver/Marker.py @@ -307,7 +307,7 @@ class Marker(QtCore.QObject): def updateLabels(self, s11data: List[Datapoint], s21data: List[Datapoint]): if self.location != -1: re50, im50 = RFTools.normalize50(s11data[self.location]) - vswr = RFTools.calculateVSWR(s11data[self.location]) + vswr = s11data[self.location].as_vswr() if re50 > 0: rp = (re50 ** 2 + im50 ** 2) / re50 rp = round(rp, 3 - max(0, math.floor(math.log10(abs(rp))))) diff --git a/NanoVNASaver/NanoVNASaver.py b/NanoVNASaver/NanoVNASaver.py index e1ede46..c928bdc 100644 --- a/NanoVNASaver/NanoVNASaver.py +++ b/NanoVNASaver/NanoVNASaver.py @@ -750,7 +750,7 @@ class NanoVNASaver(QtWidgets.QWidget): min_vswr = 100 min_vswr_freq = -1 for d in self.data: - vswr = RFTools.calculateVSWR(d) + vswr = d.as_vswr() if min_vswr > vswr > 0: min_vswr = vswr min_vswr_freq = d.freq diff --git a/NanoVNASaver/RFTools.py b/NanoVNASaver/RFTools.py index 13e570b..8a2ecc8 100644 --- a/NanoVNASaver/RFTools.py +++ b/NanoVNASaver/RFTools.py @@ -56,6 +56,8 @@ class Datapoint(NamedTuple): mag = abs(self.z) if mag == 1: return 1 + elif mag > 1: + return math.inf return (1 + mag) / (1 - mag) def to_impedance(self, ref_impedance: float = 50) -> complex: @@ -98,10 +100,6 @@ class RFTools: def qualityFactor(data: Datapoint) -> float: return data.to_q_factor() - @staticmethod - def calculateVSWR(data: Datapoint) -> float: - return data.as_vswr() - @staticmethod def capacitanceEquivalent(im50, freq) -> str: if im50 == 0 or freq == 0: