4
4
#include " unit.h"
5
5
#include " CustomWidgets/informationbox.h"
6
6
#include " appwindow.h"
7
+ #include " Util/util.h"
7
8
8
9
#include < QDialog>
9
10
#include < QHBoxLayout>
@@ -54,6 +55,17 @@ void MatchingNetwork::transformDatapoint(VirtualDevice::VNAMeasurement &p)
54
55
// at this point the map contains the matching network effect
55
56
auto m = matching[p.frequency ];
56
57
VirtualDevice::VNAMeasurement uncorrected = p;
58
+
59
+ auto portReflectionName = " S" +QString::number (port)+QString::number (port);
60
+ if (!uncorrected.measurements .count (portReflectionName)) {
61
+ // the reflection measurement for the port to de-embed is not included, nothing can be done
62
+ return ;
63
+ }
64
+ // calculate internal reflection at the matching port
65
+ auto portReflectionS = uncorrected.measurements [portReflectionName];
66
+ auto matchingReflectionS = Sparam (m.forward , p.Z0 ).m22 ;
67
+ auto internalPortReflectionS = matchingReflectionS / (1.0 - matchingReflectionS * portReflectionS);
68
+
57
69
// handle the measurements
58
70
for (auto &meas : p.measurements ) {
59
71
QString name = meas.first ;
@@ -78,9 +90,20 @@ void MatchingNetwork::transformDatapoint(VirtualDevice::VNAMeasurement &p)
78
90
}
79
91
} else {
80
92
// through measurement
81
- // Already handled by reflection measurement (toSparam uses S12/S21 as well)
82
- // and if the corresponding reflection measurement is not available, we can't
83
- // do anything anyway
93
+ if (i != port && j != port) {
94
+ try {
95
+ // find through measurements from these two ports to and from the embedding port
96
+ auto toPort = uncorrected.measurements [" S" +QString::number (port)+QString::number (j)];
97
+ auto fromPort = uncorrected.measurements [" S" +QString::number (i)+QString::number (port)];
98
+ p.measurements [name] = p.measurements [name] + toPort * internalPortReflectionS * fromPort;
99
+ } catch (...) {
100
+ // missing measurements, nothing can be done
101
+ }
102
+ } else {
103
+ // Already handled by reflection measurement (toSparam uses S12/S21 as well)
104
+ // and if the corresponding reflection measurement is not available, we can't
105
+ // do anything anyway
106
+ }
84
107
}
85
108
}
86
109
}
0 commit comments