Loading of RFSim files. Some crashes fixed when using simulated data, some still left.

pull/42/head
Rune Broberg 2019-09-30 10:37:58 +02:00
rodzic 9c0eccea12
commit b862c148a8
4 zmienionych plików z 21 dodań i 11 usunięć

Wyświetl plik

@ -410,8 +410,8 @@ class FrequencyChart(Chart):
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])

Wyświetl plik

@ -190,7 +190,8 @@ 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(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)
@ -204,6 +205,6 @@ class Marker(QtCore.QObject):
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}")

Wyświetl plik

@ -742,7 +742,11 @@ class NanoVNASaver(QtWidgets.QWidget):
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("")
@ -774,9 +778,11 @@ class NanoVNASaver(QtWidgets.QWidget):
@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
@ -822,7 +828,10 @@ class NanoVNASaver(QtWidgets.QWidget):
# 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):

Wyświetl plik

@ -53,7 +53,7 @@ class Touchstone:
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))
@ -72,7 +72,7 @@ class Touchstone:
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))