Skip to content

Commit 20d8993

Browse files
committed
vna_qt: add impedance, capacitance, and inductance graph views
1 parent 1fb44ae commit 20d8993

File tree

5 files changed

+144
-42
lines changed

5 files changed

+144
-42
lines changed

vna_qt/mainwindow.C

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,7 @@ void MainWindow::loadSettings() {
114114
refreshRecentFiles();
115115
cks = settings.value("calkits").value<CalKitSettings>();
116116

117-
nv.graphLimits = {
118-
{-1000,-999, 12},
119-
{-70, 30, 10}, //TYPE_MAG=1
120-
{-180, 180, 10}, //TYPE_PHASE
121-
{0, 50, 10}, //TYPE_GRPDELAY
122-
{1, 11, 10}, //TYPE_SWR
123-
{-1000,-999, 10} //TYPE_COMPLEX
124-
};
117+
nv.graphLimits = NetworkView::defaultGraphLimits;
125118
}
126119

127120
void MainWindow::populateCalTypes() {

vna_qt/markerslider.ui

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</property>
2222
<layout class="QHBoxLayout" name="horizontalLayout">
2323
<property name="spacing">
24-
<number>6</number>
24+
<number>3</number>
2525
</property>
2626
<property name="topMargin">
2727
<number>0</number>
@@ -123,13 +123,13 @@
123123
<string notr="true">color: red; font-weight: bold</string>
124124
</property>
125125
<property name="text">
126-
<string>TextLabel</string>
126+
<string>-100.1 Ω</string>
127127
</property>
128128
<property name="alignment">
129129
<set>Qt::AlignCenter</set>
130130
</property>
131131
<property name="margin">
132-
<number>5</number>
132+
<number>0</number>
133133
</property>
134134
</widget>
135135
</item>
@@ -145,13 +145,13 @@
145145
<string notr="true">color: blue; font-weight: bold</string>
146146
</property>
147147
<property name="text">
148-
<string>TextLabel</string>
148+
<string>TextLabel1</string>
149149
</property>
150150
<property name="alignment">
151151
<set>Qt::AlignCenter</set>
152152
</property>
153153
<property name="margin">
154-
<number>5</number>
154+
<number>0</number>
155155
</property>
156156
</widget>
157157
</item>

vna_qt/networkview.C

Lines changed: 115 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,30 @@
1616
using namespace std;
1717
using namespace xaxaxa;
1818

19+
const vector<array<double,3> > NetworkView::defaultGraphLimits = {
20+
{-1000,-999, 12},
21+
{-80, 30, 11}, //TYPE_MAG=1
22+
{-180, 180, 12}, //TYPE_PHASE
23+
{0, 50, 10}, //TYPE_GRPDELAY
24+
{1, 11, 10}, //TYPE_SWR
25+
{0, 200, 10}, //TYPE_Z_RE
26+
{-200, 200, 10}, //TYPE_Z_IM
27+
{0, 200, 10}, //TYPE_Z_MAG
28+
{0, 1000, 10}, //TYPE_Z_CAP
29+
{0, 1000, 10}, //TYPE_Z_IND
30+
{0, 1000, 10}, //TYPE_Y_RE
31+
{-1000, 1000, 10}, //TYPE_Y_IM
32+
{0, 1000, 10}, //TYPE_Y_MAG
33+
{0, 1000, 10}, //TYPE_Y_CAP
34+
{0, 1000, 10}, //TYPE_Y_IND
35+
{-1000,-999, 10} //TYPE_COMPLEX
36+
};
37+
1938
NetworkView::NetworkView() {
2039
xAxisValueStr = [](double val) {
2140
return to_string(val);
2241
};
23-
graphLimits = {
24-
{-1000,-999, 12},
25-
{-80, 30, 11}, //TYPE_MAG=1
26-
{-180, 180, 12}, //TYPE_PHASE
27-
{0, 50, 10}, //TYPE_GRPDELAY
28-
{1, 11, 10}, //TYPE_SWR
29-
{-1000,-999, 10} //TYPE_COMPLEX
30-
};
42+
graphLimits = NetworkView::defaultGraphLimits;
3143
}
3244

3345
void NetworkView::init(QLayout *sliderContainer) {
@@ -55,12 +67,30 @@ GraphPanel* NetworkView::createGraphView(bool freqDomain, bool tr) {
5567
case SParamViewSource::TYPE_MAG: name = "mag"; break;
5668
case SParamViewSource::TYPE_PHASE: name = "arg"; break;
5769
case SParamViewSource::TYPE_SWR: name = "swr"; break;
70+
case SParamViewSource::TYPE_Z_RE: name = "Z_re"; break;
71+
case SParamViewSource::TYPE_Z_IM: name = "Z_im"; break;
72+
case SParamViewSource::TYPE_Z_MAG: name = "|Z|"; break;
73+
case SParamViewSource::TYPE_Z_CAP: name = "Cseries"; break;
74+
case SParamViewSource::TYPE_Z_IND: name = "Lseries"; break;
75+
case SParamViewSource::TYPE_Y_RE: name = "Y_re"; break;
76+
case SParamViewSource::TYPE_Y_IM: name = "Y_im"; break;
77+
case SParamViewSource::TYPE_Y_MAG: name = "|Y|"; break;
78+
case SParamViewSource::TYPE_Y_CAP: name = "Cparallel"; break;
79+
case SParamViewSource::TYPE_Y_IND: name = "Lparallel"; break;
5880
}
5981
for(int row=0;row<2;row++)
6082
for(int col=0;col<2;col++) {
6183
if(tr && col==1) continue;
84+
6285
// group delay only makes sense in frequency domain view
6386
if(!freqDomain && i==SParamViewSource::TYPE_GRPDELAY) continue;
87+
88+
// impedance parameters only make sense for Snn, not Snm,
89+
// and also only in frequency domain.
90+
if(i >= SParamViewSource::TYPE_Z_RE && i <= SParamViewSource::TYPE_Y_IND) {
91+
if(row != col) continue;
92+
if(!freqDomain) continue;
93+
}
6494
string desc = name + "(S" + to_string(row+1) + to_string(col+1) + ")";
6595
graphTraces.push_back(desc);
6696
graphSources.push_back({row, col, SParamViewSource::Types(i)});
@@ -116,6 +146,16 @@ void NetworkView::updateXAxis(double start, double step, int cnt) {
116146
case SParamViewSource::TYPE_SWR:
117147
case SParamViewSource::TYPE_PHASE:
118148
case SParamViewSource::TYPE_GRPDELAY:
149+
case SParamViewSource::TYPE_Z_RE:
150+
case SParamViewSource::TYPE_Z_IM:
151+
case SParamViewSource::TYPE_Z_MAG:
152+
case SParamViewSource::TYPE_Z_CAP:
153+
case SParamViewSource::TYPE_Z_IND:
154+
case SParamViewSource::TYPE_Y_RE:
155+
case SParamViewSource::TYPE_Y_IM:
156+
case SParamViewSource::TYPE_Y_MAG:
157+
case SParamViewSource::TYPE_Y_CAP:
158+
case SParamViewSource::TYPE_Y_IND:
119159
{
120160
auto* series = dynamic_cast<QLineSeries*>(tmp.view);
121161
series->clear();
@@ -160,17 +200,19 @@ void NetworkView::updateView(int viewIndex, int freqIndex) {
160200
}
161201
return;
162202
}
203+
double freqHz = xAxisAt(freqIndex)*1e6; // only meaningful in frequency domain
163204
SParamView tmp = this->views.at(viewIndex);
164205

165206
VNACalibratedValue val = this->values.at(freqIndex);
166207
complex<double> entry = val(tmp.src.row,tmp.src.col);
208+
double z0 = 50;
209+
complex<double> Z = -z0*(entry+1.)/(entry-1.);
210+
complex<double> Y = -(entry-1.)/(z0*(entry+1.));
167211

168-
switch(tmp.src.type) {
169-
case SParamViewSource::TYPE_MAG:
170-
case SParamViewSource::TYPE_SWR:
171-
case SParamViewSource::TYPE_PHASE:
172-
case SParamViewSource::TYPE_GRPDELAY:
173-
{
212+
if(tmp.src.type == SParamViewSource::TYPE_COMPLEX) {
213+
auto* view = dynamic_cast<PolarView*>(tmp.view);
214+
view->points.at(freqIndex) = entry;
215+
} else {
174216
auto* series = dynamic_cast<QLineSeries*>(tmp.view);
175217
double y = 0;
176218
switch(tmp.src.type) {
@@ -183,6 +225,36 @@ void NetworkView::updateView(int viewIndex, int freqIndex) {
183225
case SParamViewSource::TYPE_PHASE:
184226
y = arg(entry)*180./M_PI;
185227
break;
228+
case SParamViewSource::TYPE_Z_RE:
229+
y = Z.real();
230+
break;
231+
case SParamViewSource::TYPE_Z_IM:
232+
y = Z.imag();
233+
break;
234+
case SParamViewSource::TYPE_Z_MAG:
235+
y = abs(Z);
236+
break;
237+
case SParamViewSource::TYPE_Z_CAP: // capacitance in pF
238+
y = -capacitance_inductance(freqHz, Z.imag()) * 1e12;
239+
break;
240+
case SParamViewSource::TYPE_Z_IND: // inductance in nH
241+
y = capacitance_inductance(freqHz, Z.imag()) * 1e9;
242+
break;
243+
case SParamViewSource::TYPE_Y_RE:
244+
y = Y.real() * 1000;
245+
break;
246+
case SParamViewSource::TYPE_Y_IM:
247+
y = Y.imag() * 1000;
248+
break;
249+
case SParamViewSource::TYPE_Y_MAG:
250+
y = abs(Y) * 1000;
251+
break;
252+
case SParamViewSource::TYPE_Y_CAP: // capacitance in pF
253+
y = -capacitance_inductance_Y(freqHz, Y.imag()) * 1e12;
254+
break;
255+
case SParamViewSource::TYPE_Y_IND: // inductance in nH
256+
y = capacitance_inductance_Y(freqHz, Y.imag()) * 1e9;
257+
break;
186258
case SParamViewSource::TYPE_GRPDELAY:
187259
{
188260
if(freqIndex>0) {
@@ -197,16 +269,26 @@ void NetworkView::updateView(int viewIndex, int freqIndex) {
197269
}
198270
default: assert(false);
199271
}
272+
273+
// clamp values to avoid enlarging labels
274+
switch(tmp.src.type) {
275+
case SParamViewSource::TYPE_Z_CAP:
276+
case SParamViewSource::TYPE_Z_IND:
277+
case SParamViewSource::TYPE_Y_CAP:
278+
case SParamViewSource::TYPE_Y_IND:
279+
if(y < 0) y = 0;
280+
if(y > 999) y = 999;
281+
break;
282+
case SParamViewSource::TYPE_Z_RE:
283+
case SParamViewSource::TYPE_Z_IM:
284+
case SParamViewSource::TYPE_Z_MAG:
285+
if(y < -999) y = -999;
286+
if(y > 999) y = 999;
287+
break;
288+
default: break;
289+
}
290+
200291
series->replace(freqIndex,series->at(freqIndex).x(), y);
201-
break;
202-
}
203-
case SParamViewSource::TYPE_COMPLEX:
204-
{
205-
auto* view = dynamic_cast<PolarView*>(tmp.view);
206-
view->points.at(freqIndex) = entry;
207-
break;
208-
}
209-
default: assert(false);
210292
}
211293
}
212294

@@ -262,6 +344,16 @@ void NetworkView::updateBottomLabels(int marker) {
262344
case SParamViewSource::TYPE_SWR: fmt = "%.2lf:1"; break;
263345
case SParamViewSource::TYPE_PHASE: fmt = "%.1lf °"; break;
264346
case SParamViewSource::TYPE_GRPDELAY: fmt = "%.2lf ns"; break;
347+
case SParamViewSource::TYPE_Z_RE: fmt = "%.1lf Ω"; break;
348+
case SParamViewSource::TYPE_Z_IM: fmt = "%.1lf Ω"; break;
349+
case SParamViewSource::TYPE_Z_MAG: fmt = "%.1lf Ω"; break;
350+
case SParamViewSource::TYPE_Z_CAP: fmt = "%.1lf pF"; break;
351+
case SParamViewSource::TYPE_Z_IND: fmt = "%.2lf nH"; break;
352+
case SParamViewSource::TYPE_Y_RE: fmt = "%.1lf mS"; break;
353+
case SParamViewSource::TYPE_Y_IM: fmt = "%.1lf mS"; break;
354+
case SParamViewSource::TYPE_Y_MAG: fmt = "%.1lf mS"; break;
355+
case SParamViewSource::TYPE_Y_CAP: fmt = "%.1lf pF"; break;
356+
case SParamViewSource::TYPE_Y_IND: fmt = "%.2lf nH"; break;
265357
default: fmt = "%.2lf";
266358
}
267359
marker.ms->setLabelText(j, ssprintf(32, fmt, series->at(marker.freqIndex).y()));

vna_qt/networkview.H

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ struct SParamViewSource {
2424
int row,col; // which S parameter are we viewing
2525
enum Types {
2626
UNDEFINED=0,
27-
TYPE_MAG=1, // view must be QLineSeries
28-
TYPE_PHASE, // view must be QLineSeries
29-
TYPE_GRPDELAY, // view must be QLineSeries
30-
TYPE_SWR, // view must be QLineSeries
31-
TYPE_COMPLEX, // view must be PolarView
27+
// view must be QLineSeries:
28+
TYPE_MAG=1, // display the magnitude of Snn
29+
TYPE_PHASE, // display the phase of Snn
30+
TYPE_GRPDELAY, // group delay calculated from change in phase
31+
TYPE_SWR, // standing wave ratio
32+
TYPE_Z_RE, // real part of series equivalent impedance
33+
TYPE_Z_IM, // imaginary part of series equivalent impedance
34+
TYPE_Z_MAG, // magnitude of series equivalent impedance
35+
TYPE_Z_CAP, // capacitance (in pF), series equivalent
36+
TYPE_Z_IND, // inductance (in nH), series equivalent
37+
TYPE_Y_RE, // real part of parallel equivalent admittance, mS
38+
TYPE_Y_IM, // imaginary part of parallel equivalent admittance, mS
39+
TYPE_Y_MAG, // magnitude of parallel equivalent admittance, mS
40+
TYPE_Y_CAP, // capacitance (in pF), parallel equivalent
41+
TYPE_Y_IND, // inductance (in nH), parallel equivalent
42+
// view must be PolarView:
43+
TYPE_COMPLEX,
3244
_LAST
3345
} type;
3446
};
@@ -84,6 +96,7 @@ public:
8496
// min, max, and division count of the y axis of the graph, indexed by SParamViewSource::Types
8597
vector<array<double,3> > graphLimits;
8698

99+
static const vector<array<double,3> > defaultGraphLimits;
87100

88101

89102
NetworkView();

vna_qt/utility.H

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ inline double swr(double power) {
2323
return (double)fmin(11.0,(d+1)/(d-1));
2424
}
2525

26-
// freq is in Hz, Z is in ohms
26+
// freq is in Hz, Z is in ohms.
27+
// if return value is positive, it is in henries;
28+
// if return value is negative, it is in farads.
2729
inline double capacitance_inductance(double freq, double Z) {
2830
if(Z>0) return Z/(2*M_PI*freq);
2931
return 1./(2*Z*M_PI*freq);
3032
}
3133
// freq is in Hz, Y is in mhos
34+
// if return value is positive, it is in henries;
35+
// if return value is negative, it is in farads.
3236
inline double capacitance_inductance_Y(double freq, double Y) {
3337
if(Y<0) return -1./(2*Y*M_PI*freq);
3438
return -Y/(2*M_PI*freq);

0 commit comments

Comments
 (0)