| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "markdown", |
| 5 |
"metadata": { |
| 6 |
"pycharm": { |
| 7 |
"name": "#%% md\n" |
| 8 |
} |
| 9 |
}, |
| 10 |
"source": [ |
| 11 |
"# Mixed Mode S-Parameter Conversion\n", |
| 12 |
"\n", |
| 13 |
"When analyzing differential devices, mixed-mode S-Parameters are typically used to look at differential and common mode\n", |
| 14 |
"characteristics. Scikit-rf provides functions to ease conversion between single ended and mixed mode S-parameters.\n", |
| 15 |
"Nevertheless, the user must be careful to set up ports correctly and take note of the form of the mixed-mode matrix to\n", |
| 16 |
"prevent confusion. This notebook will introduce you to the process of converting from single ended to mixed mode S\n", |
| 17 |
"parameters using a [50 ohm calibration load](https://www.formfactor.com/download/iss-map-129-246/) as an example.\n", |
| 18 |
"The experimental port setup consists of two differential probes as shown:\n", |
| 19 |
"\n", |
| 20 |
"<img src=\"mixedmodebasics_files/setup.PNG\">\n", |
| 21 |
"\n", |
| 22 |
"Experimental data for the 50 ohm load taken in normal \"single ended\" mode will be compared against data saved in\n", |
| 23 |
"a mixed mode format and taken using Keysight's integrated True Mode Stimulus, which applies true differential\n", |
| 24 |
"and common mode signals during the measurement process." |
| 25 |
] |
| 26 |
}, |
| 27 |
{ |
| 28 |
"cell_type": "code", |
| 29 |
"execution_count": null, |
| 30 |
"metadata": { |
| 31 |
"pycharm": { |
| 32 |
"name": "#%%\n" |
| 33 |
} |
| 34 |
}, |
| 35 |
"outputs": [], |
| 36 |
"source": [ |
| 37 |
"import re\n", |
| 38 |
"\n", |
| 39 |
"import matplotlib.pyplot as plt\n", |
| 40 |
"import numpy as np\n", |
| 41 |
"\n", |
| 42 |
"import skrf as rf\n", |
| 43 |
"\n", |
| 44 |
"sedatafile = r'mixedmodebasics_files/load_se.s4p'\n", |
| 45 |
"mmdatafile = r'mixedmodebasics_files/load_truemode_balbal.s4p'\n", |
| 46 |
"\n", |
| 47 |
"for file in [sedatafile, mmdatafile]:\n", |
| 48 |
" with open(file, encoding='cp1252') as f:\n", |
| 49 |
" for line in f:\n", |
| 50 |
" print(line.rstrip())\n", |
| 51 |
" if re.search('#', line):\n", |
| 52 |
" break\n", |
| 53 |
" else:\n", |
| 54 |
" pass\n", |
| 55 |
" print('\\n')" |
| 56 |
] |
| 57 |
}, |
| 58 |
{ |
| 59 |
"cell_type": "markdown", |
| 60 |
"metadata": { |
| 61 |
"pycharm": { |
| 62 |
"name": "#%% md\n" |
| 63 |
} |
| 64 |
}, |
| 65 |
"source": [ |
| 66 |
"The header data for the mixed mode data indicates that it is saved in the following format:\n", |
| 67 |
"\n", |
| 68 |
"$$\n", |
| 69 |
"\\begin{bmatrix}\n", |
| 70 |
"\\begin{bmatrix}\n", |
| 71 |
" S_{dd} & S_{dc} \\\\\n", |
| 72 |
" S_{cd} & S_{cc}\n", |
| 73 |
"\\end{bmatrix}_{11} &\n", |
| 74 |
"\\begin{bmatrix}\n", |
| 75 |
" S_{dd} & S_{dc} \\\\\n", |
| 76 |
" S_{cd} & S_{cc}\n", |
| 77 |
"\\end{bmatrix}_{12} \\\\\n", |
| 78 |
"\\begin{bmatrix}\n", |
| 79 |
" S_{dd} & S_{dc} \\\\\n", |
| 80 |
" S_{cd} & S_{cc}\n", |
| 81 |
"\\end{bmatrix}_{21} &\n", |
| 82 |
"\\begin{bmatrix}\n", |
| 83 |
" S_{dd} & S_{dc} \\\\\n", |
| 84 |
" S_{cd} & S_{cc}\n", |
| 85 |
"\\end{bmatrix}_{22}\n", |
| 86 |
"\\end{bmatrix}\n", |
| 87 |
"$$\n", |
| 88 |
"\n", |
| 89 |
"It is important to keep this in mind, as this format may vary between different software and hardware.\n", |
| 90 |
"For instance, skrf will transform singled ended data to the following form when two balanced ports are present:\n", |
| 91 |
"\n", |
| 92 |
"$$\n", |
| 93 |
"\\begin{bmatrix}\n", |
| 94 |
"\\begin{bmatrix}\n", |
| 95 |
" S_{11} & S_{12} \\\\\n", |
| 96 |
" S_{21} & S_{22}\n", |
| 97 |
"\\end{bmatrix}_{dd} &\n", |
| 98 |
"\\begin{bmatrix}\n", |
| 99 |
" S_{11} & S_{12} \\\\\n", |
| 100 |
" S_{21} & S_{22}\n", |
| 101 |
"\\end{bmatrix}_{dc} \\\\\n", |
| 102 |
"\\begin{bmatrix}\n", |
| 103 |
" S_{11} & S_{12} \\\\\n", |
| 104 |
" S_{21} & S_{22}\n", |
| 105 |
"\\end{bmatrix}_{cd} &\n", |
| 106 |
"\\begin{bmatrix}\n", |
| 107 |
" S_{11} & S_{12} \\\\\n", |
| 108 |
" S_{21} & S_{22}\n", |
| 109 |
"\\end{bmatrix}_{cc}\n", |
| 110 |
"\\end{bmatrix}\n", |
| 111 |
"$$\n", |
| 112 |
"\n", |
| 113 |
"To transform our single ended data, we must first pair the ports as they existed during the experimental setup with\n", |
| 114 |
"ports 1 and 3 making up one balanced port, and 2 and 4 on the other probe. We can then use the `se2gmm()` method of the\n", |
| 115 |
"skrf.Network class to transform to a mixed mode s-parameter matrix, with the `p` parameter used to specify the number of\n", |
| 116 |
"mixed mode ports. Skrf will transform the ports in pairs starting at the lowest number ports (1 and 3 after our\n", |
| 117 |
"renumbering) and continue until the matrix contains `p` mixed mode ports, leaving the remaining ports as single ended." |
| 118 |
] |
| 119 |
}, |
| 120 |
{ |
| 121 |
"cell_type": "code", |
| 122 |
"execution_count": null, |
| 123 |
"metadata": { |
| 124 |
"pycharm": { |
| 125 |
"name": "#%%\n" |
| 126 |
} |
| 127 |
}, |
| 128 |
"outputs": [], |
| 129 |
"source": [ |
| 130 |
"sedata = rf.Network(sedatafile)\n", |
| 131 |
"sedata.renumber([0, 1, 2, 3], [0, 2, 1, 3]) # pair ports as 1,3 and 2,4 to match experimental setup\n", |
| 132 |
"sedata.se2gmm(p=2) # two balanced ports\n", |
| 133 |
"# sedata now in form Sdd Sdc with each submatrix as S11 S12\n", |
| 134 |
"# Scd Scc S21 S22" |
| 135 |
] |
| 136 |
}, |
| 137 |
{ |
| 138 |
"cell_type": "markdown", |
| 139 |
"metadata": { |
| 140 |
"pycharm": { |
| 141 |
"name": "#%% md\n" |
| 142 |
} |
| 143 |
}, |
| 144 |
"source": [ |
| 145 |
"The following function converts a two-port balanced-balanced network in the skrf format into the format used by\n", |
| 146 |
"Keysight to make data comparisons easier:" |
| 147 |
] |
| 148 |
}, |
| 149 |
{ |
| 150 |
"cell_type": "code", |
| 151 |
"execution_count": null, |
| 152 |
"metadata": { |
| 153 |
"pycharm": { |
| 154 |
"name": "#%%\n" |
| 155 |
} |
| 156 |
}, |
| 157 |
"outputs": [], |
| 158 |
"source": [ |
| 159 |
"def gmm_reorder(m):\n", |
| 160 |
" \"\"\"\n", |
| 161 |
" Reorders data from form 11 12 with each submatrix as dd dc\n", |
| 162 |
" 21 22 cd cc\n", |
| 163 |
" to form dd dc with each submatrix as 11 12\n", |
| 164 |
" cd cc 21 22\n", |
| 165 |
" \"\"\"\n", |
| 166 |
" b = np.array([1, 0, 0, 0,\n", |
| 167 |
" 0, 0, 1, 0,\n", |
| 168 |
" 0, 1, 0, 0,\n", |
| 169 |
" 0, 0, 0, 1]).reshape(4, 4)\n", |
| 170 |
" m = b.dot(m.dot(b))\n", |
| 171 |
" return m\n", |
| 172 |
"\n", |
| 173 |
"mmdata = rf.Network(mmdatafile)\n", |
| 174 |
"# raw data is mmdata in form S11 S12 with each submatrix as dd dc\n", |
| 175 |
"# S21 S22 cd cc\n", |
| 176 |
"for i in range(mmdata.frequency.npoints):\n", |
| 177 |
" mmdata.s[i, :, :] = gmm_reorder(mmdata.s[i, :, :])\n", |
| 178 |
"mmdata.port_modes = ['D', 'D', 'C', 'C']" |
| 179 |
] |
| 180 |
}, |
| 181 |
{ |
| 182 |
"cell_type": "markdown", |
| 183 |
"metadata": {}, |
| 184 |
"source": [ |
| 185 |
"Now that the two networks are in the same format, we can see that skrf does not consider them equal.\n", |
| 186 |
"This is because the networks are not identical, they are merely two measurements of the same device, both with\n", |
| 187 |
"experimental noise and variation. \n", |
| 188 |
"If the tolerances of the comparison are relaxed, the comparison of the networks returns True:" |
| 189 |
] |
| 190 |
}, |
| 191 |
{ |
| 192 |
"cell_type": "code", |
| 193 |
"execution_count": null, |
| 194 |
"metadata": { |
| 195 |
"pycharm": { |
| 196 |
"name": "#%%\n" |
| 197 |
} |
| 198 |
}, |
| 199 |
"outputs": [], |
| 200 |
"source": [ |
| 201 |
"print(sedata == mmdata) # uses np.allclose with tight tolerances\n", |
| 202 |
"print(np.allclose(abs(sedata.s), abs(mmdata.s), rtol=1, atol=1e-3)) # relaxed tolerances" |
| 203 |
] |
| 204 |
}, |
| 205 |
{ |
| 206 |
"cell_type": "markdown", |
| 207 |
"metadata": {}, |
| 208 |
"source": [ |
| 209 |
"Plotted, the error looks like this:" |
| 210 |
] |
| 211 |
}, |
| 212 |
{ |
| 213 |
"cell_type": "code", |
| 214 |
"execution_count": null, |
| 215 |
"metadata": { |
| 216 |
"pycharm": { |
| 217 |
"name": "#%%\n" |
| 218 |
}, |
| 219 |
"scrolled": false |
| 220 |
}, |
| 221 |
"outputs": [], |
| 222 |
"source": [ |
| 223 |
"for m in range(4):\n", |
| 224 |
" for n in range(4):\n", |
| 225 |
" plt.plot(sedata.f, abs(mmdata.s)[:,m,n]-abs(sedata.s)[:,m,n], label=f'S{sedata._fmt_trace_name(m, n)}')\n", |
| 226 |
" plt.title('Magnitude Error between Measurements')\n", |
| 227 |
" plt.legend(bbox_to_anchor=(1.1, 1.05))\n", |
| 228 |
"\n" |
| 229 |
] |
| 230 |
}, |
| 231 |
{ |
| 232 |
"cell_type": "code", |
| 233 |
"execution_count": null, |
| 234 |
"metadata": {}, |
| 235 |
"outputs": [], |
| 236 |
"source": [ |
| 237 |
"fig, axes = plt.subplots(2,2, sharex=True, sharey='row', figsize=(14,6))\n", |
| 238 |
"sedata.plot_s_db(ax=axes[0][0])\n", |
| 239 |
"mmdata.plot_s_db(ax=axes[0][1])\n", |
| 240 |
"sedata.plot_s_deg(ax=axes[1][0])\n", |
| 241 |
"mmdata.plot_s_deg(ax=axes[1][1])\n", |
| 242 |
"axes[0][0].get_legend().remove()\n", |
| 243 |
"axes[1][0].get_legend().remove()\n", |
| 244 |
"axes[1][1].get_legend().remove()\n", |
| 245 |
"axes[0][1].get_legend().remove()\n", |
| 246 |
"axes[0][0].set_title('sedata Magnitude')\n", |
| 247 |
"axes[0][1].set_title('mmdata Magnitude')\n", |
| 248 |
"axes[1][0].set_title('sedata Phase')\n", |
| 249 |
"axes[1][1].set_title('mmdata Phase')\n", |
| 250 |
"\n", |
| 251 |
"fig.legend(*axes[0, 1].get_legend_handles_labels(), loc=\"center right\")\n", |
| 252 |
"fig.tight_layout()\n", |
| 253 |
"plt.subplots_adjust(top=0.9, right=0.8)\n", |
| 254 |
"\n" |
| 255 |
] |
| 256 |
}, |
| 257 |
{ |
| 258 |
"cell_type": "code", |
| 259 |
"execution_count": null, |
| 260 |
"metadata": { |
| 261 |
"pycharm": { |
| 262 |
"name": "#%%\n" |
| 263 |
} |
| 264 |
}, |
| 265 |
"outputs": [], |
| 266 |
"source": [ |
| 267 |
"fig, axes = plt.subplots(4,4, sharex=True, figsize=(14,8))\n", |
| 268 |
"for m in range(4):\n", |
| 269 |
" for n in range(4):\n", |
| 270 |
" sedata.plot_s_deg_unwrap(m=m, n=n, ax=axes[m][n])\n", |
| 271 |
" mmdata.plot_s_deg_unwrap(m=m, n=n, ax=axes[m][n], ls='--')\n", |
| 272 |
" axes[m][n].get_legend().remove()\n", |
| 273 |
" axes[m][n].set_title(f'S{sedata._fmt_trace_name(m, n)}')\n", |
| 274 |
"fig.tight_layout()" |
| 275 |
] |
| 276 |
}, |
| 277 |
{ |
| 278 |
"cell_type": "code", |
| 279 |
"execution_count": null, |
| 280 |
"metadata": {}, |
| 281 |
"outputs": [], |
| 282 |
"source": [] |
| 283 |
} |
| 284 |
], |
| 285 |
"metadata": { |
| 286 |
"kernelspec": { |
| 287 |
"display_name": "Python 3 (ipykernel)", |
| 288 |
"language": "python", |
| 289 |
"name": "python3" |
| 290 |
}, |
| 291 |
"language_info": { |
| 292 |
"codemirror_mode": { |
| 293 |
"name": "ipython", |
| 294 |
"version": 3 |
| 295 |
}, |
| 296 |
"file_extension": ".py", |
| 297 |
"mimetype": "text/x-python", |
| 298 |
"name": "python", |
| 299 |
"nbconvert_exporter": "python", |
| 300 |
"pygments_lexer": "ipython3", |
| 301 |
"version": "3.9.16" |
| 302 |
} |
| 303 |
}, |
| 304 |
"nbformat": 4, |
| 305 |
"nbformat_minor": 1 |
| 306 |
} |