Skip to content

Commit

Permalink
Loading of RFSim files. Some crashes fixed when using simulated data,…
Browse files Browse the repository at this point in the history
… some still left.
  • Loading branch information
mihtjel committed Sep 30, 2019
1 parent 9c0ecce commit b862c14
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions NanoVNASaver/Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ def drawMarkers(self, qp):
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)

def isPlotable(self, x, y):
return self.leftMargin < x <= self.leftMargin + self.chartWidth and \
self.topMargin < y <= self.topMargin + self.chartHeight
return self.leftMargin <= x <= self.leftMargin + self.chartWidth and \
self.topMargin <= y <= self.topMargin + self.chartHeight

def getPlotable(self, x, y, distantx, distanty):
p1 = np.array([x, y])
Expand Down
5 changes: 3 additions & 2 deletions NanoVNASaver/Marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ def updateLabels(self, s11data: List[Datapoint], s21data: List[Datapoint]):
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(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)
self.inductance_label.setText(inductance)
Expand All @@ -204,6 +205,6 @@ def updateLabels(self, s11data: List[Datapoint], s21data: List[Datapoint]):
str(round(PhaseChart.angle(s11data[self.location]), 2)) + "\N{DEGREE SIGN}")
if len(s21data) == len(s11data):
_, _, vswr = NanoVNASaver.vswr(s21data[self.location])
self.gain_label.setText(str(round(20 * math.log10((vswr - 1) / (vswr + 1)), 3)) + " dB")
self.gain_label.setText(str(round(NanoVNASaver.gain(s21data[self.location]), 3)) + " dB")
self.s21_phase_label.setText(
str(round(PhaseChart.angle(s21data[self.location]), 2)) + "\N{DEGREE SIGN}")
19 changes: 14 additions & 5 deletions NanoVNASaver/NanoVNASaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,11 @@ def dataUpdated(self):

if minVSWRfreq > -1:
self.s11_min_swr_label.setText(str(round(minVSWR, 3)) + " @ " + self.formatFrequency(minVSWRfreq))
self.s11_min_rl_label.setText(str(round(20*math.log10((minVSWR-1)/(minVSWR+1)), 3)) + " dB")
if minVSWR > 1:
self.s11_min_rl_label.setText(str(round(20*math.log10((minVSWR-1)/(minVSWR+1)), 3)) + " dB")
else:
# Infinite return loss?
self.s11_min_rl_label.setText("\N{INFINITY} dB")
else:
self.s11_min_swr_label.setText("")
self.s11_min_rl_label.setText("")
Expand Down Expand Up @@ -774,9 +778,11 @@ def dataUpdated(self):
@staticmethod
def vswr(data: Datapoint):
re50, im50 = NanoVNASaver.normalize50(data)
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt((re50 + 50) * (re50 + 50) + im50 * im50)
# mag = math.sqrt(re * re + im * im) # Is this even right?
vswr = (1 + mag) / (1 - mag)
try:
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt((re50 + 50) * (re50 + 50) + im50 * im50)
vswr = (1 + mag) / (1 - mag)
except ZeroDivisionError as e:
vswr = 1
return im50, re50, vswr

@staticmethod
Expand Down Expand Up @@ -822,7 +828,10 @@ def gain(data: Datapoint):
# Calculate the gain / reflection coefficient
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt(
(re50 + 50) * (re50 + 50) + im50 * im50)
return 20 * math.log10(mag)
if mag > 0:
return 20 * math.log10(mag)
else:
return 0

@staticmethod
def normalize50(data):
Expand Down
4 changes: 2 additions & 2 deletions NanoVNASaver/Touchstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def load(self):
logger.info(line)
continue
if line.startswith("#") and not parsed_header:
pattern = "^# (.?HZ) S RI R 50$"
pattern = "^# (.?HZ) (S )?RI( R 50)?$"
match = re.match(pattern, line.upper())
if match:
logger.debug("Found header for RealImaginary and %s", match.group(1))
Expand All @@ -72,7 +72,7 @@ def load(self):
factor = 10**9 # Default Touchstone frequency unit is GHz
continue

pattern = "^# (.?HZ) S MA R 50$"
pattern = "^# (.?HZ) (S )?MA( R 50)?$"
match = re.match(pattern, line.upper())
if match:
logger.debug("Found header for MagnitudeAngle and %s", match.group(1))
Expand Down

0 comments on commit b862c14

Please sign in to comment.