diff --git a/Software/PC_Application/LibreVNA-GUI/Calibration/CalStandardThroughEditDialog.ui b/Software/PC_Application/LibreVNA-GUI/Calibration/CalStandardThroughEditDialog.ui
index 7dfd09ce..4746bd0b 100644
--- a/Software/PC_Application/LibreVNA-GUI/Calibration/CalStandardThroughEditDialog.ui
+++ b/Software/PC_Application/LibreVNA-GUI/Calibration/CalStandardThroughEditDialog.ui
@@ -72,7 +72,7 @@
-
- false
+ true
diff --git a/Software/PC_Application/LibreVNA-GUI/Calibration/calstandard.cpp b/Software/PC_Application/LibreVNA-GUI/Calibration/calstandard.cpp
index ea0f26ca..942a0233 100644
--- a/Software/PC_Application/LibreVNA-GUI/Calibration/calstandard.cpp
+++ b/Software/PC_Application/LibreVNA-GUI/Calibration/calstandard.cpp
@@ -579,7 +579,13 @@ Sparam Through::toSparam(double freq)
double through_att = pow(10.0, -through_att_db / 10.0);
auto through = polar(through_att, through_phaseshift);
// Assume symmetric and perfectly matched through for other parameters
- return Sparam(0.0, through, through, 0.0);
+ auto S = Sparam(0.0, through, through, 0.0);
+ // update S parameters if Z0 does not match system impedance exactly
+ if(Z0 != 50.0) {
+ auto abcd = ABCDparam(S, Z0);
+ S = Sparam(abcd, 50.0);
+ }
+ return S;
}
}
diff --git a/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro b/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro
index 6f7f79ed..08634f39 100644
--- a/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro
+++ b/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro
@@ -150,6 +150,7 @@ SOURCES += \
../LibreVNA-GUI/touchstone.cpp \
../LibreVNA-GUI/unit.cpp \
main.cpp \
+ parametertests.cpp \
portextensiontests.cpp \
utiltests.cpp
@@ -339,6 +340,7 @@ HEADERS += \
../LibreVNA-GUI/tcpserver.h \
../LibreVNA-GUI/touchstone.h \
../LibreVNA-GUI/unit.h \
+ parametertests.h \
portextensiontests.h \
utiltests.h
diff --git a/Software/PC_Application/LibreVNA-Test/main.cpp b/Software/PC_Application/LibreVNA-Test/main.cpp
index 0dff291d..610ad4ca 100644
--- a/Software/PC_Application/LibreVNA-Test/main.cpp
+++ b/Software/PC_Application/LibreVNA-Test/main.cpp
@@ -1,5 +1,6 @@
#include "utiltests.h"
#include "portextensiontests.h"
+#include "parametertests.h"
#include
@@ -10,6 +11,7 @@ int main(int argc, char *argv[])
int status = 0;
status |= QTest::qExec(new UtilTests, argc, argv);
status |= QTest::qExec(new PortExtensionTests, argc, argv);
+ status |= QTest::qExec(new ParameterTests, argc, argv);
return status;
}
diff --git a/Software/PC_Application/LibreVNA-Test/parametertests.cpp b/Software/PC_Application/LibreVNA-Test/parametertests.cpp
new file mode 100644
index 00000000..c41b06b4
--- /dev/null
+++ b/Software/PC_Application/LibreVNA-Test/parametertests.cpp
@@ -0,0 +1,63 @@
+#include "parametertests.h"
+
+#include "Tools/parameters.h"
+
+#include
+
+ParameterTests::ParameterTests()
+{
+
+}
+
+void ParameterTests::S2ABCD()
+{
+ using namespace std::complex_literals;
+
+ std::complex S11 = 0.0038 + 0.0248i;
+ std::complex S12 = 0.9961 - 0.0250i;
+ std::complex S21 = 0.9964 - 0.0254i;
+ std::complex S22 = 0.0037 + 0.0249i;
+ auto S = Sparam(S11, S12, S21, S22);
+ auto abcd = ABCDparam(S, 50.0);
+
+ std::complex A = 0.99988705861501226 + 0.00014900771660107621i;
+ std::complex B = 0.31256891513454765 + 2.5194422425174801i;
+ std::complex C = -2.7673838933081734e-09 + 6.9983236736743502e-06i;
+ std::complex D = 0.99978420576400329 + 0.00024674711602337137i;
+
+ QVERIFY(qFuzzyCompare(abcd.m11.real(), A.real()));
+ QVERIFY(qFuzzyCompare(abcd.m11.imag(), A.imag()));
+ QVERIFY(qFuzzyCompare(abcd.m12.real(), B.real()));
+ QVERIFY(qFuzzyCompare(abcd.m12.imag(), B.imag()));
+ QVERIFY(qFuzzyCompare(abcd.m21.real(), C.real()));
+ QVERIFY(qFuzzyCompare(abcd.m21.imag(), C.imag()));
+ QVERIFY(qFuzzyCompare(abcd.m22.real(), D.real()));
+ QVERIFY(qFuzzyCompare(abcd.m22.imag(), D.imag()));
+}
+
+void ParameterTests::ABCD2S()
+{
+ using namespace std::complex_literals;
+
+ std::complex A = 0.99988705861501226 + 0.00014900771660107621i;
+ std::complex B = 0.31256891513454765 + 2.5194422425174801i;
+ std::complex C = -2.7673838933081734e-09 + 6.9983236736743502e-06i;
+ std::complex D = 0.99978420576400329 + 0.00024674711602337137i;
+ auto abcd = ABCDparam(A, B, C, D);
+
+ auto s = Sparam(abcd, 50.0);
+
+ std::complex S11 = 0.0038 + 0.0248i;
+ std::complex S12 = 0.9961 - 0.0250i;
+ std::complex S21 = 0.9964 - 0.0254i;
+ std::complex S22 = 0.0037 + 0.0249i;
+
+ QVERIFY(qFuzzyCompare(s.m11.real(), S11.real()));
+ QVERIFY(qFuzzyCompare(s.m11.imag(), S11.imag()));
+ QVERIFY(qFuzzyCompare(s.m12.real(), S12.real()));
+ QVERIFY(qFuzzyCompare(s.m12.imag(), S12.imag()));
+ QVERIFY(qFuzzyCompare(s.m21.real(), S21.real()));
+ QVERIFY(qFuzzyCompare(s.m21.imag(), S21.imag()));
+ QVERIFY(qFuzzyCompare(s.m22.real(), S22.real()));
+ QVERIFY(qFuzzyCompare(s.m22.imag(), S22.imag()));
+}
diff --git a/Software/PC_Application/LibreVNA-Test/parametertests.h b/Software/PC_Application/LibreVNA-Test/parametertests.h
new file mode 100644
index 00000000..743187d8
--- /dev/null
+++ b/Software/PC_Application/LibreVNA-Test/parametertests.h
@@ -0,0 +1,17 @@
+#ifndef PARAMETERTESTS_H
+#define PARAMETERTESTS_H
+
+#include
+
+class ParameterTests : public QObject
+{
+ Q_OBJECT
+public:
+ ParameterTests();
+
+private slots:
+ void S2ABCD();
+ void ABCD2S();
+};
+
+#endif // PARAMETERTESTS_H