kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Loading of RFSim files. Some crashes fixed when using simulated data, some still left.
rodzic
9c0eccea12
commit
b862c148a8
|
@ -410,8 +410,8 @@ class FrequencyChart(Chart):
|
||||||
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
|
qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)
|
||||||
|
|
||||||
def isPlotable(self, x, y):
|
def isPlotable(self, x, y):
|
||||||
return self.leftMargin < x <= self.leftMargin + self.chartWidth and \
|
return self.leftMargin <= x <= self.leftMargin + self.chartWidth and \
|
||||||
self.topMargin < y <= self.topMargin + self.chartHeight
|
self.topMargin <= y <= self.topMargin + self.chartHeight
|
||||||
|
|
||||||
def getPlotable(self, x, y, distantx, distanty):
|
def getPlotable(self, x, y, distantx, distanty):
|
||||||
p1 = np.array([x, y])
|
p1 = np.array([x, y])
|
||||||
|
|
|
@ -190,7 +190,8 @@ class Marker(QtCore.QObject):
|
||||||
self.impedance_label.setText(str(re50) + im50str)
|
self.impedance_label.setText(str(re50) + im50str)
|
||||||
self.parallel_r_label.setText(str(rp) + " \N{OHM SIGN}")
|
self.parallel_r_label.setText(str(rp) + " \N{OHM SIGN}")
|
||||||
self.parallel_x_label.setText(xpstr)
|
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)
|
capacitance = NanoVNASaver.capacitanceEquivalent(im50, s11data[self.location].freq)
|
||||||
inductance = NanoVNASaver.inductanceEquivalent(im50, s11data[self.location].freq)
|
inductance = NanoVNASaver.inductanceEquivalent(im50, s11data[self.location].freq)
|
||||||
self.inductance_label.setText(inductance)
|
self.inductance_label.setText(inductance)
|
||||||
|
@ -204,6 +205,6 @@ class Marker(QtCore.QObject):
|
||||||
str(round(PhaseChart.angle(s11data[self.location]), 2)) + "\N{DEGREE SIGN}")
|
str(round(PhaseChart.angle(s11data[self.location]), 2)) + "\N{DEGREE SIGN}")
|
||||||
if len(s21data) == len(s11data):
|
if len(s21data) == len(s11data):
|
||||||
_, _, vswr = NanoVNASaver.vswr(s21data[self.location])
|
_, _, 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(
|
self.s21_phase_label.setText(
|
||||||
str(round(PhaseChart.angle(s21data[self.location]), 2)) + "\N{DEGREE SIGN}")
|
str(round(PhaseChart.angle(s21data[self.location]), 2)) + "\N{DEGREE SIGN}")
|
||||||
|
|
|
@ -742,7 +742,11 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
|
|
||||||
if minVSWRfreq > -1:
|
if minVSWRfreq > -1:
|
||||||
self.s11_min_swr_label.setText(str(round(minVSWR, 3)) + " @ " + self.formatFrequency(minVSWRfreq))
|
self.s11_min_swr_label.setText(str(round(minVSWR, 3)) + " @ " + self.formatFrequency(minVSWRfreq))
|
||||||
|
if minVSWR > 1:
|
||||||
self.s11_min_rl_label.setText(str(round(20*math.log10((minVSWR-1)/(minVSWR+1)), 3)) + " dB")
|
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:
|
else:
|
||||||
self.s11_min_swr_label.setText("")
|
self.s11_min_swr_label.setText("")
|
||||||
self.s11_min_rl_label.setText("")
|
self.s11_min_rl_label.setText("")
|
||||||
|
@ -774,9 +778,11 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def vswr(data: Datapoint):
|
def vswr(data: Datapoint):
|
||||||
re50, im50 = NanoVNASaver.normalize50(data)
|
re50, im50 = NanoVNASaver.normalize50(data)
|
||||||
|
try:
|
||||||
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt((re50 + 50) * (re50 + 50) + im50 * im50)
|
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)
|
vswr = (1 + mag) / (1 - mag)
|
||||||
|
except ZeroDivisionError as e:
|
||||||
|
vswr = 1
|
||||||
return im50, re50, vswr
|
return im50, re50, vswr
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -822,7 +828,10 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
# Calculate the gain / reflection coefficient
|
# Calculate the gain / reflection coefficient
|
||||||
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt(
|
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt(
|
||||||
(re50 + 50) * (re50 + 50) + im50 * im50)
|
(re50 + 50) * (re50 + 50) + im50 * im50)
|
||||||
|
if mag > 0:
|
||||||
return 20 * math.log10(mag)
|
return 20 * math.log10(mag)
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def normalize50(data):
|
def normalize50(data):
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Touchstone:
|
||||||
logger.info(line)
|
logger.info(line)
|
||||||
continue
|
continue
|
||||||
if line.startswith("#") and not parsed_header:
|
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())
|
match = re.match(pattern, line.upper())
|
||||||
if match:
|
if match:
|
||||||
logger.debug("Found header for RealImaginary and %s", match.group(1))
|
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
|
factor = 10**9 # Default Touchstone frequency unit is GHz
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pattern = "^# (.?HZ) S MA R 50$"
|
pattern = "^# (.?HZ) (S )?MA( R 50)?$"
|
||||||
match = re.match(pattern, line.upper())
|
match = re.match(pattern, line.upper())
|
||||||
if match:
|
if match:
|
||||||
logger.debug("Found header for MagnitudeAngle and %s", match.group(1))
|
logger.debug("Found header for MagnitudeAngle and %s", match.group(1))
|
||||||
|
|
Ładowanie…
Reference in New Issue