Skip to content

Commit 83f91a7

Browse files
committed
Adding a plot for S11 Parameter
1 parent c6a13e8 commit 83f91a7

12 files changed

Lines changed: 138 additions & 421 deletions

smith_chart/index.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ <h4 class="mb-0"><strong>ONLINE SMITH CHART TOOL</strong></h4>
268268
</div>
269269

270270
<div class="row mt-4">
271-
<div class="col-lg-6">
271+
272+
<div class="col-lg-4">
273+
<div class="row text-center"><h4 class="mb-0">S11 Parameter vs Frequency</h4></div>
274+
<div class="row" id="smith_sparameters">
275+
<div>
276+
<div id="SParamPlot"><!-- Plotly chart will be drawn inside this DIV --></div>
277+
</div>
278+
</div>
279+
</div>
280+
281+
<div class="col-lg-4">
272282
<div class="row text-center"><h4 class="mb-0">Reflection Coefficient plotted on a polar axes</h4></div>
273283
<div class="row" id="smith_polar">
274284
<div>
@@ -277,7 +287,7 @@ <h4 class="mb-0"><strong>ONLINE SMITH CHART TOOL</strong></h4>
277287
</div>
278288
</div>
279289

280-
<div class="col-lg-6">
290+
<div class="col-lg-4">
281291
<div class="row text-center"><h4 class="mb-0"><small>Distance to Vmax and Vmin</small></h4></div>
282292
<div class="row" id="smith_lambda">
283293
<div>

smith_chart/js/smith_tool.js

Lines changed: 126 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//parameters
22
var resolution = 100;// 100; //number of points per arc
3-
var span_resolution = 10;
3+
var span_resolution = 20;
44
var precision=3;
55

66

@@ -373,6 +373,22 @@ function update_schem_component(freq_here,save_impedance,sch_index) {
373373
//update_smith_chart();
374374
}
375375

376+
function impedanceToReflectionCoefficient (real_old, imag_old, zo) {
377+
//Calculate the reflection coefficient -current_admittance (zo-zimp) / (zo+zimp)
378+
var bot_real,bot_imag;
379+
temp_array = one_over_complex(real_old*zo + zo,imag_old*zo);
380+
bot_real= temp_array[0];
381+
bot_imag = temp_array[1];
382+
var reflectio_coeff_real = ((real_old*zo - zo) * bot_real) - ((imag_old*zo)*bot_imag);
383+
var reflectio_coeff_imag = ((imag_old*zo) * bot_real) + ((real_old*zo - zo) * bot_imag);
384+
var reflection_mag = Math.sqrt((reflectio_coeff_real*reflectio_coeff_real)+(reflectio_coeff_imag*reflectio_coeff_imag));
385+
if (reflectio_coeff_real == 0) var reflection_phase = 0;
386+
else var reflection_phase = 360*Math.atan(reflectio_coeff_imag/reflectio_coeff_real)/(2*Math.PI);
387+
if (reflectio_coeff_real < 0) reflection_phase += 180;
388+
if (reflection_phase < 0) reflection_phase = 360 + reflection_phase;
389+
return [reflectio_coeff_real, reflectio_coeff_imag, reflection_mag, reflection_phase];
390+
}
391+
376392
//TODO - A big improvement here would be to separate out the impedance calculation and arc drawing. It should calculate impedances, then calculate points along the arc
377393
function update_smith_chart() {
378394
//Update the layout variable
@@ -621,27 +637,15 @@ function update_smith_chart() {
621637
document.getElementById("current_admittance").innerHTML = txt
622638

623639
//Calculate the reflection coefficient -current_admittance (zo-zimp) / (zo+zimp)
624-
var bot_real,bot_imag;
625-
temp_array = one_over_complex(real_old*zo + zo,imag_old*zo);
626-
bot_real= temp_array[0];
627-
bot_imag = temp_array[1];
628-
var reflectio_coeff_real = ((real_old*zo - zo) * bot_real) - ((imag_old*zo)*bot_imag);
629-
var reflectio_coeff_imag = ((imag_old*zo) * bot_real) + ((real_old*zo - zo) * bot_imag);
640+
var reflectio_coeff_real, reflectio_coeff_imag, reflection_mag, reflection_phase;
641+
[reflectio_coeff_real, reflectio_coeff_imag, reflection_mag, reflection_phase] = impedanceToReflectionCoefficient (real_old, imag_old, zo)
630642
txt = "<div class=\"text_box\">"+(reflectio_coeff_real).toPrecision(3);
631643
if (reflectio_coeff_imag < 0) txt += " - ";
632644
else txt += " + ";
633645
txt += Math.abs(reflectio_coeff_imag).toPrecision(3) + "j</div>";
634646
document.getElementById("current_reflection").innerHTML = txt;
635-
636-
//plot reflection coefficient magnitude
637-
//console.log(reflectio_coeff_imag,reflectio_coeff_real);
638-
var reflection_mag = Math.sqrt((reflectio_coeff_real*reflectio_coeff_real)+(reflectio_coeff_imag*reflectio_coeff_imag));
639-
txt = "<div class=\"text_box\">"+reflection_mag.toPrecision(3);
647+
txt = "<div class=\"text_box\">"+reflection_mag.toPrecision(3);
640648
txt += " &ang; ";
641-
if (reflectio_coeff_real == 0) var reflection_phase = 0;
642-
else var reflection_phase = 360*Math.atan(reflectio_coeff_imag/reflectio_coeff_real)/(2*Math.PI);
643-
if (reflectio_coeff_real < 0) reflection_phase += 180;
644-
if (reflection_phase < 0) reflection_phase = 360 + reflection_phase;
645649
txt += (reflection_phase).toPrecision(3) + "&deg; </div>";
646650
document.getElementById("current_reflection_mag").innerHTML = txt;
647651

@@ -765,7 +769,9 @@ function update_smith_chart() {
765769

766770
var data = trace.concat(textbox_trace,trace_im_neg,trace_im_pos,trace_real,trace_adm,trace_sus_pos,trace_sus_neg,span_trace,constQ_trace);
767771

768-
//console.log(data, layout, layout_shapes);
772+
//
773+
//Create a plot for reflection coefficient plotted on its own
774+
//
769775
var exWidth = document.getElementById("myDiv").offsetWidth
770776
// var exWidth = document.getElementById("myDiv").offsetWidth
771777
var PlLayout = {
@@ -781,7 +787,7 @@ function update_smith_chart() {
781787
shapes:layout.shapes.concat(layout_shapes)
782788
};
783789
var config = {
784-
displayModeBar: false, // this is the line that hides the bar.
790+
displayModeBar: false, // this is the line that hides the hover bar.
785791
};
786792
Plotly.react('myDiv', data, PlLayout, config);
787793

@@ -849,8 +855,9 @@ var layout_polar = {
849855
layout_polar.height = polarWidth;
850856
Plotly.react('PolarPlot', data_polar, layout_polar, config)
851857

852-
853-
//Create the plots for distance to Vmax and Vmin
858+
//
859+
//Create a plots for distance to Vmax and Vmin
860+
//
854861
var markX, markY;
855862
[markX, markY] = find_smith_coord(real_old,imag_old,false)
856863

@@ -1000,6 +1007,105 @@ var layout_polar = {
10001007
layout_lambda.height = smith_lambda;
10011008
Plotly.react('LambdaPlot', data_lambda, layout_lambda, config);
10021009

1010+
//
1011+
//Create a plots showing the S-parameters
1012+
//
1013+
var traceS11 = {
1014+
line: {
1015+
color: 'blue',
1016+
},
1017+
name: 'S11 (dB)',
1018+
type: 'scatter'
1019+
};
1020+
1021+
// var traceS22 = {
1022+
// line: {
1023+
// color: 'red',
1024+
// },
1025+
// name: 'S22 (dB)',
1026+
// yaxis: 'y2',
1027+
// type: 'scatter'
1028+
// };
1029+
1030+
var sParamLayout = {
1031+
yaxis: {
1032+
tickfont: {color: 'blue'},
1033+
zeroline: false,
1034+
showgrid: true,
1035+
gridcolor: "rgb(37, 50, 64)",
1036+
fixedrange: true,
1037+
title: 'S11 (dB)',
1038+
automargin: true,
1039+
},
1040+
// yaxis2: {
1041+
// tickfont: {color: 'red'},
1042+
// side: 'right',
1043+
// zeroline: false,
1044+
// showgrid: true,
1045+
// gridcolor: "rgb(37, 50, 64)",
1046+
// fixedrange: true,
1047+
// },
1048+
xaxis: {
1049+
automargin: true,
1050+
title: 'frequency (' + domFreqSel.value + ')',
1051+
zeroline: false,
1052+
showgrid: false,
1053+
fixedrange: true,
1054+
},
1055+
autosize: true,
1056+
margin: {
1057+
l: 20,
1058+
r: 20,
1059+
b: 20,
1060+
t: 20
1061+
},
1062+
hovermode: false,
1063+
showlegend: false,
1064+
// legend: {
1065+
// x: 1,
1066+
// xanchor: 'right',
1067+
// y: 1
1068+
// },
1069+
paper_bgcolor: 'rgba(0,0,0,0)',
1070+
plot_bgcolor: 'rgba(0,0,0,0)',
1071+
1072+
};
1073+
1074+
var scaledFreq = freq/schematic[0].freq_unit.multiplier;
1075+
//just show 1 point
1076+
traceS11.y = [];
1077+
if (span_freq == 0) {
1078+
var newSpanFreq = 1
1079+
traceS11.x = [scaledFreq];
1080+
if (reflection_mag == 0) traceS11.y.push(0)
1081+
else traceS11.y.push(20*Math.log10(reflection_mag))
1082+
// traceS22.x = [scaledFreq];
1083+
// traceS22.y = [0.5];
1084+
// sParamLayout.yaxis.range = [0, 2];
1085+
// sParamLayout.yaxis2.range = [0, 2];
1086+
} else {
1087+
// [reflectio_coeff_real, reflectio_coeff_imag, reflection_mag, reflection_phase] = impedanceToReflectionCoefficient (real_old, imag_old, zo)
1088+
traceS11.x = [];
1089+
for (i=0; i<span_impedance_re.length;i++) {
1090+
[reflectio_coeff_real, reflectio_coeff_imag, reflection_mag, reflection_phase] = impedanceToReflectionCoefficient (span_impedance_re[i],span_impedance_im[i], zo)
1091+
if (reflection_mag == 0) traceS11.y.push(0)
1092+
else traceS11.y.push(20*Math.log10(reflection_mag))
1093+
traceS11.x.push((freq + span_freq * (i-span_res)/span_res)/schematic[0].freq_unit.multiplier);
1094+
}
1095+
newSpanFreq = span_freq/schematic[0].freq_unit.multiplier;
1096+
}
1097+
1098+
sParamLayout.xaxis.range = [scaledFreq - newSpanFreq, scaledFreq + newSpanFreq];
1099+
1100+
// var data = [traceS11, traceS22];
1101+
var data = [traceS11];
1102+
// var smith_lambda = document.getElementById("SParamPlot").offsetWidth;
1103+
// sParamLayout.width = smith_lambda;
1104+
// sParamLayout.height = smith_lambda;
1105+
1106+
Plotly.react('SParamPlot', data, sParamLayout, config);
1107+
1108+
10031109
//update the HTML tables
10041110
drawMakerTable();
10051111
}

smith_chart/scss/_bootstrap-overrides.scss

Lines changed: 0 additions & 51 deletions
This file was deleted.

smith_chart/scss/_contact.scss

Lines changed: 0 additions & 54 deletions
This file was deleted.

smith_chart/scss/_footer.scss

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)