11//parameters
22var resolution = 100 ; // 100; //number of points per arc
3- var span_resolution = 10 ;
3+ var span_resolution = 20 ;
44var 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
377393function 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 += " ∠ " ;
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 ) + "° </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}
0 commit comments