From 6b2506ff4bcb6e774c9f263a4564c1a546c0088a Mon Sep 17 00:00:00 2001 From: Holger Mueller Date: Sun, 17 Nov 2019 14:13:37 +0100 Subject: [PATCH] Replaced RFTools.normalize50 by Datapoint method --- NanoVNASaver/Analysis.py | 6 ++---- NanoVNASaver/Chart.py | 23 +++++++++++++---------- NanoVNASaver/Marker.py | 3 ++- NanoVNASaver/RFTools.py | 13 ++++--------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/NanoVNASaver/Analysis.py b/NanoVNASaver/Analysis.py index 83b11e9..d9b6d0f 100644 --- a/NanoVNASaver/Analysis.py +++ b/NanoVNASaver/Analysis.py @@ -1007,14 +1007,12 @@ class SimplePeakSearchAnalysis(Analysis): suffix = " \N{OHM SIGN}" data = [] for d in self.app.data: - re, im = RFTools.normalize50(d) - data.append(re) + data.append(d.impedance().real) elif self.rbtn_data_reactance.isChecked(): suffix = " \N{OHM SIGN}" data = [] for d in self.app.data: - re, im = RFTools.normalize50(d) - data.append(im) + data.append(d.impedance().imag) elif self.rbtn_data_s21_gain.isChecked(): suffix = " dB" data = [] diff --git a/NanoVNASaver/Chart.py b/NanoVNASaver/Chart.py index c7497ef..892be8c 100644 --- a/NanoVNASaver/Chart.py +++ b/NanoVNASaver/Chart.py @@ -2580,7 +2580,8 @@ class RealImaginaryChart(FrequencyChart): max_real = 0 max_imag = -1000 for d in self.data: - re, im = RFTools.normalize50(d) + imp = d.impedance() + re, im = imp.real, imp.imag if re > max_real: max_real = re if re < min_real: @@ -2592,7 +2593,8 @@ class RealImaginaryChart(FrequencyChart): for d in self.reference: # Also check min/max for the reference sweep if d.freq < fstart or d.freq > fstop: continue - re, im = RFTools.normalize50(d) + imp = d.impedance() + re, im = imp.real, imp.imag if re > max_real: max_real = re if re < min_real: @@ -2792,11 +2794,11 @@ class RealImaginaryChart(FrequencyChart): self.drawMarker(x, y_im, qp, m.color, self.markers.index(m)+1) def getImYPosition(self, d: Datapoint) -> int: - _, im = RFTools.normalize50(d) + im = d.impedance().imag return self.topMargin + round((self.max_imag - im) / self.span_imag * self.chartHeight) def getReYPosition(self, d: Datapoint) -> int: - re, _ = RFTools.normalize50(d) + re = d.impedance().real return self.topMargin + round((self.max_real - re) / self.span_real * self.chartHeight) def valueAtPosition(self, y) -> List[float]: @@ -3179,8 +3181,7 @@ class MagnitudeZChart(FrequencyChart): @staticmethod def magnitude(p: Datapoint) -> float: - re, im = RFTools.normalize50(p) - return math.sqrt(re**2 + im**2) + return abs(p.impedance()) def copy(self): new_chart: LogMagChart = super().copy() @@ -3282,7 +3283,8 @@ class PermeabilityChart(FrequencyChart): min_val = 1000 max_val = -1000 for d in self.data: - re, im = RFTools.normalize50(d) + imp = d.impedance() + re, im = imp.real, imp.imag re = re * 10e6 / d.freq im = im * 10e6 / d.freq if re > max_val: @@ -3296,7 +3298,8 @@ class PermeabilityChart(FrequencyChart): for d in self.reference: # Also check min/max for the reference sweep if d.freq < fstart or d.freq > fstop: continue - re, im = RFTools.normalize50(d) + imp = d.impedance() + re, im = imp.real, imp.imag re = re * 10e6 / d.freq im = im * 10e6 / d.freq if re > max_val: @@ -3461,7 +3464,7 @@ class PermeabilityChart(FrequencyChart): self.drawMarker(x, y_im, qp, m.color, self.markers.index(m)+1) def getImYPosition(self, d: Datapoint) -> int: - _, im = RFTools.normalize50(d) + im = d.impedance().imag im = im * 10e6 / d.freq if self.logarithmicY: min_val = self.max - self.span @@ -3474,7 +3477,7 @@ class PermeabilityChart(FrequencyChart): return self.topMargin + round((self.max - im) / self.span * self.chartHeight) def getReYPosition(self, d: Datapoint) -> int: - re, _ = RFTools.normalize50(d) + re = d.impedance().real re = re * 10e6 / d.freq if self.logarithmicY: min_val = self.max - self.span diff --git a/NanoVNASaver/Marker.py b/NanoVNASaver/Marker.py index 46fc841..4c77e60 100644 --- a/NanoVNASaver/Marker.py +++ b/NanoVNASaver/Marker.py @@ -306,7 +306,8 @@ class Marker(QtCore.QObject): def updateLabels(self, s11data: List[Datapoint], s21data: List[Datapoint]): if self.location != -1: - re50, im50 = RFTools.normalize50(s11data[self.location]) + imp = s11data[self.location].impedance() + re50, im50 = imp.real, imp.imag vswr = s11data[self.location].vswr if re50 > 0: rp = (re50 ** 2 + im50 ** 2) / re50 diff --git a/NanoVNASaver/RFTools.py b/NanoVNASaver/RFTools.py index 844618b..018177e 100644 --- a/NanoVNASaver/RFTools.py +++ b/NanoVNASaver/RFTools.py @@ -62,11 +62,11 @@ class Datapoint(NamedTuple): return math.inf return (1 + mag) / (1 - mag) - def to_impedance(self, ref_impedance: float = 50) -> complex: + def impedance(self, ref_impedance: float = 50) -> complex: return ref_impedance * ((-self.z - 1) / (self.z - 1)) def q_factor(self, ref_impedance: float = 50) -> float: - imp = self.to_impedance(ref_impedance) + imp = self.impedance(ref_impedance) if imp.real == 0.0: return -1 return abs(imp.imag / imp.real) @@ -74,7 +74,7 @@ class Datapoint(NamedTuple): def to_capacitive_equivalent(self, ref_impedance: float = 50) -> float: if self.freq == 0: return math.inf - imp = self.to_impedance(ref_impedance) + imp = self.impedance(ref_impedance) if imp.imag == 0: return math.inf return -(1 / (self.freq * 2 * math.pi * imp.imag)) @@ -82,18 +82,13 @@ class Datapoint(NamedTuple): def to_inductive_equivalent(self, ref_impedance: float = 50) -> float: if self.freq == 0: return math.inf - imp = self.to_impedance(ref_impedance) + imp = self.impedance(ref_impedance) if imp.imag == 0: return 0 return imp.imag * 1 / (self.freq * 2 * math.pi) class RFTools: - @staticmethod - def normalize50(data: Datapoint): - result = data.to_impedance() - return result.real, result.imag - @staticmethod def capacitanceEquivalent(im50, freq) -> str: if im50 == 0 or freq == 0: