kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
- Handling of real and imaginary pure 0 values, for example from sims.
rodzic
1397aef995
commit
0d46ab633e
|
@ -1057,13 +1057,8 @@ class LogMagChart(FrequencyChart):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def logMag(p: Datapoint) -> float:
|
def logMag(p: Datapoint) -> float:
|
||||||
re = p.re
|
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
||||||
im = p.im
|
return NanoVNASaver.gain(p)
|
||||||
re50 = 50 * (1 - re * re - im * im) / (1 + re * re + im * im - 2 * re)
|
|
||||||
im50 = 50 * (2 * im) / (1 + re * re + im * im - 2 * re)
|
|
||||||
# Calculate the reflection coefficient
|
|
||||||
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt((re50 + 50) * (re50 + 50) + im50 * im50)
|
|
||||||
return -20 * math.log10(mag)
|
|
||||||
|
|
||||||
|
|
||||||
class QualityFactorChart(FrequencyChart):
|
class QualityFactorChart(FrequencyChart):
|
||||||
|
|
|
@ -85,7 +85,6 @@ class Marker(QtCore.QObject):
|
||||||
|
|
||||||
line = QtWidgets.QFrame()
|
line = QtWidgets.QFrame()
|
||||||
line.setFrameShape(QtWidgets.QFrame.VLine)
|
line.setFrameShape(QtWidgets.QFrame.VLine)
|
||||||
#line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
||||||
|
|
||||||
left_form = QtWidgets.QFormLayout()
|
left_form = QtWidgets.QFormLayout()
|
||||||
right_form = QtWidgets.QFormLayout()
|
right_form = QtWidgets.QFormLayout()
|
||||||
|
@ -169,12 +168,24 @@ class Marker(QtCore.QObject):
|
||||||
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
from NanoVNASaver.NanoVNASaver import NanoVNASaver
|
||||||
if self.location != -1:
|
if self.location != -1:
|
||||||
im50, re50, vswr = NanoVNASaver.vswr(s11data[self.location])
|
im50, re50, vswr = NanoVNASaver.vswr(s11data[self.location])
|
||||||
rp = (re50 ** 2 + im50 ** 2) / re50
|
if re50 > 0:
|
||||||
xp = (re50 ** 2 + im50 ** 2) / im50
|
rp = (re50 ** 2 + im50 ** 2) / re50
|
||||||
re50 = round(re50, 4 - max(0, math.floor(math.log10(abs(re50)))))
|
rp = round(rp, 4 - max(0, math.floor(math.log10(abs(rp)))))
|
||||||
rp = round(rp, 4 - max(0, math.floor(math.log10(abs(rp)))))
|
|
||||||
im50 = round(im50, 4 - max(0, math.floor(math.log10(abs(im50)))))
|
re50 = round(re50, 4 - max(0, math.floor(math.log10(abs(re50)))))
|
||||||
xp = round(xp, 4 - max(0, math.floor(math.log10(abs(xp)))))
|
else:
|
||||||
|
rp = 0
|
||||||
|
re50 = 0
|
||||||
|
|
||||||
|
if im50 > 0:
|
||||||
|
xp = (re50 ** 2 + im50 ** 2) / im50
|
||||||
|
xp = round(xp, 4 - max(0, math.floor(math.log10(abs(xp)))))
|
||||||
|
else:
|
||||||
|
xp = 0
|
||||||
|
|
||||||
|
if im50 != 0:
|
||||||
|
im50 = round(im50, 4 - max(0, math.floor(math.log10(abs(im50)))))
|
||||||
|
|
||||||
if im50 < 0:
|
if im50 < 0:
|
||||||
im50str = " -j" + str(-1 * im50)
|
im50str = " -j" + str(-1 * im50)
|
||||||
else:
|
else:
|
||||||
|
@ -190,7 +201,6 @@ 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(NanoVNASaver.gain(s11data[self.location]), 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)
|
||||||
|
@ -200,7 +210,12 @@ class Marker(QtCore.QObject):
|
||||||
if vswr < 0:
|
if vswr < 0:
|
||||||
vswr = "-"
|
vswr = "-"
|
||||||
self.vswr_label.setText(str(vswr))
|
self.vswr_label.setText(str(vswr))
|
||||||
self.quality_factor_label.setText(str(round(NanoVNASaver.qualifyFactor(s11data[self.location]), 1)))
|
q = NanoVNASaver.qualifyFactor(s11data[self.location])
|
||||||
|
if q > 10000 or q < 0:
|
||||||
|
q_str = "\N{INFINITY}"
|
||||||
|
else:
|
||||||
|
q_str = str(round(q, 1))
|
||||||
|
self.quality_factor_label.setText(q_str)
|
||||||
self.s11_phase_label.setText(
|
self.s11_phase_label.setText(
|
||||||
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):
|
||||||
|
|
|
@ -795,10 +795,10 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
def qualifyFactor(data: Datapoint):
|
def qualifyFactor(data: Datapoint):
|
||||||
im50, re50, _ = NanoVNASaver.vswr(data)
|
im50, re50, _ = NanoVNASaver.vswr(data)
|
||||||
if re50 != 0:
|
if re50 != 0:
|
||||||
Q = im50 / re50
|
Q = abs(im50 / re50)
|
||||||
else:
|
else:
|
||||||
Q = 0
|
Q = -1
|
||||||
return abs(Q)
|
return Q
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def capacitanceEquivalent(im50, freq) -> str:
|
def capacitanceEquivalent(im50, freq) -> str:
|
||||||
|
@ -818,7 +818,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
||||||
def inductanceEquivalent(im50, freq) -> str:
|
def inductanceEquivalent(im50, freq) -> str:
|
||||||
if freq == 0:
|
if freq == 0:
|
||||||
return "- nH"
|
return "- nH"
|
||||||
inductance = im50 * 1000000000/ (freq * 2 * math.pi)
|
inductance = im50 * 1000000000 / (freq * 2 * math.pi)
|
||||||
if abs(inductance) > 10000:
|
if abs(inductance) > 10000:
|
||||||
return str(round(inductance / 1000, 2)) + " μH"
|
return str(round(inductance / 1000, 2)) + " μH"
|
||||||
elif abs(inductance) > 1000:
|
elif abs(inductance) > 1000:
|
||||||
|
|
Ładowanie…
Reference in New Issue