| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "markdown", |
| 5 |
"metadata": {}, |
| 6 |
"source": [ |
| 7 |
"# Export Network Set as Generalized MDIF File" |
| 8 |
] |
| 9 |
}, |
| 10 |
{ |
| 11 |
"cell_type": "markdown", |
| 12 |
"metadata": {}, |
| 13 |
"source": [ |
| 14 |
"Frequently a set of `Networks` is recorded while changing some other parameters; like temperature, voltage, current, etc. Once this set of data acquired, it is sometime useful to combine all the networks into a single Generalized MDIF file for use in CAD tools like AWR Microwave Office." |
| 15 |
] |
| 16 |
}, |
| 17 |
{ |
| 18 |
"cell_type": "code", |
| 19 |
"execution_count": null, |
| 20 |
"metadata": {}, |
| 21 |
"outputs": [], |
| 22 |
"source": [ |
| 23 |
"import pathlib\n", |
| 24 |
"import tempfile\n", |
| 25 |
"import zipfile\n", |
| 26 |
"\n", |
| 27 |
"import numpy as np\n", |
| 28 |
"import requests\n", |
| 29 |
"\n", |
| 30 |
"import skrf as rf" |
| 31 |
] |
| 32 |
}, |
| 33 |
{ |
| 34 |
"cell_type": "markdown", |
| 35 |
"metadata": {}, |
| 36 |
"source": [ |
| 37 |
"## Narda 3752 phase shifter" |
| 38 |
] |
| 39 |
}, |
| 40 |
{ |
| 41 |
"cell_type": "markdown", |
| 42 |
"metadata": {}, |
| 43 |
"source": [ |
| 44 |
"In this example, we are characterizing an old [narda phase shifter 3752](https://nardamiteq.com/docs/119-PHASESHIFTERS.PDF) at 1.5 GHz. \n", |
| 45 |
"\n", |
| 46 |
"\n", |
| 47 |
"\n", |
| 48 |
"\n", |
| 49 |
"In order to deduce the phase shift that one can obtain at this specific frequency, we have measured scattering parameters in the 1-2 GHz band at 19 positions of the phase knob (from 0 to 180). These measurements are loaded into a [NetworkSets](../../tutorials/NetworkSet.ipynb) object:" |
| 50 |
] |
| 51 |
}, |
| 52 |
{ |
| 53 |
"cell_type": "code", |
| 54 |
"execution_count": null, |
| 55 |
"metadata": {}, |
| 56 |
"outputs": [], |
| 57 |
"source": [ |
| 58 |
"# Array containing the 19 phase shift indicator values\n", |
| 59 |
"indicators_mes = np.linspace(0, 180, num=19) # from 0 to 180 per 10" |
| 60 |
] |
| 61 |
}, |
| 62 |
{ |
| 63 |
"cell_type": "code", |
| 64 |
"execution_count": null, |
| 65 |
"metadata": {}, |
| 66 |
"outputs": [], |
| 67 |
"source": [ |
| 68 |
"ntw_set = rf.NetworkSet.from_zip('phase_shifter_measurements/phase_shifter_measurements.zip')\n", |
| 69 |
"print('ntw_set contains', len(ntw_set), 'networks')" |
| 70 |
] |
| 71 |
}, |
| 72 |
{ |
| 73 |
"cell_type": "markdown", |
| 74 |
"metadata": {}, |
| 75 |
"source": [ |
| 76 |
"The content of the NetworkSet can be exported into a MDIF file:" |
| 77 |
] |
| 78 |
}, |
| 79 |
{ |
| 80 |
"cell_type": "code", |
| 81 |
"execution_count": null, |
| 82 |
"metadata": {}, |
| 83 |
"outputs": [], |
| 84 |
"source": [ |
| 85 |
"ntw_set.write_mdif(\"phase_shifter.mdif\")" |
| 86 |
] |
| 87 |
}, |
| 88 |
{ |
| 89 |
"cell_type": "markdown", |
| 90 |
"metadata": {}, |
| 91 |
"source": [ |
| 92 |
"Note that is possible to tune the parameters, values and types defined in the MDIF file by passing the optional parameters `values` and `data_types`. Hence, making \"indicator\" an MDIF variable of type \"double\" and save the NetworkSet to \"phase_shifter.mdif\":" |
| 93 |
] |
| 94 |
}, |
| 95 |
{ |
| 96 |
"cell_type": "code", |
| 97 |
"execution_count": null, |
| 98 |
"metadata": {}, |
| 99 |
"outputs": [], |
| 100 |
"source": [ |
| 101 |
"values = {\"indicator\": indicators_mes}\n", |
| 102 |
"data_types = {\"indicator\": \"double\"}\n", |
| 103 |
"ntw_set.write_mdif(\"phase_shifter.mdif\", values, data_types)" |
| 104 |
] |
| 105 |
}, |
| 106 |
{ |
| 107 |
"cell_type": "markdown", |
| 108 |
"metadata": {}, |
| 109 |
"source": [ |
| 110 |
"## ADRF5720\n", |
| 111 |
"\n", |
| 112 |
"[ADRF5720](https://www.analog.com/en/products/adrf5720.html) is 6-bit 9 kHz to 40 GHz digital step attenuator and is measured over temperature which results in many Touchstone files." |
| 113 |
] |
| 114 |
}, |
| 115 |
{ |
| 116 |
"cell_type": "code", |
| 117 |
"execution_count": null, |
| 118 |
"metadata": {}, |
| 119 |
"outputs": [], |
| 120 |
"source": [ |
| 121 |
"# download the zip archive of ADRF5720 Touchstone files\n", |
| 122 |
"url = \"https://www.analog.com/media/en/simulation-models/s-parameters/ADRF5720_Sparameters.zip\"\n", |
| 123 |
"try:\n", |
| 124 |
" response = requests.get(url, timeout=10)\n", |
| 125 |
" open(\"ADRF5720.zip\", \"wb\").write(response.content)\n", |
| 126 |
" tmpdir = pathlib.Path(tempfile.mkdtemp())\n", |
| 127 |
" zf = zipfile.ZipFile(\"ADRF5720.zip\")\n", |
| 128 |
" zf.extractall(path = tmpdir)\n", |
| 129 |
" zf.close()\n", |
| 130 |
"\n", |
| 131 |
" # filter out one file (which contains '5720_noDC')\n", |
| 132 |
" input_files = [file for file in tmpdir.rglob('*.s2p') if '5720_noDC' not in file.stem]\n", |
| 133 |
" ns = rf.NetworkSet(rf.read_all(files=[str(file) for file in input_files]))\n", |
| 134 |
" print('ns contains', len(ns), 'networks')\n", |
| 135 |
"\n", |
| 136 |
" # extract the attenuation value from the filenames and store in list\n", |
| 137 |
" attn = []\n", |
| 138 |
" temp = []\n", |
| 139 |
" for f in input_files:\n", |
| 140 |
" _,_,_,_,_,a,t = f.stem.split('_')\n", |
| 141 |
" t = t.replace('M','-').replace('C','')\n", |
| 142 |
" attn.append(float(a))\n", |
| 143 |
" temp.append(int(t))\n", |
| 144 |
"\n", |
| 145 |
" # sort files\n", |
| 146 |
" v = list(zip(attn,temp,input_files))\n", |
| 147 |
" v.sort()\n", |
| 148 |
" (attn,temp,input_files) = list(zip(*v))\n", |
| 149 |
"\n", |
| 150 |
" values = {'ATTEN': attn, 'TEMP_C': temp }\n", |
| 151 |
" datatypes = {'ATTEN': 'double', 'TEMP_C': 'double'}\n", |
| 152 |
"\n", |
| 153 |
" # write to a generalized MDIF file\n", |
| 154 |
" ns.write_mdif(\"ADRF5720.mdif\", values, datatypes)\n", |
| 155 |
"\n", |
| 156 |
"except requests.ReadTimeout:\n", |
| 157 |
" print('Timeout... skipping this example')" |
| 158 |
] |
| 159 |
}, |
| 160 |
{ |
| 161 |
"cell_type": "markdown", |
| 162 |
"metadata": {}, |
| 163 |
"source": [ |
| 164 |
"Finally, the parameterized MDIF files can be imported into AWR Microwave Office:\n", |
| 165 |
"\n", |
| 166 |
"" |
| 167 |
] |
| 168 |
} |
| 169 |
], |
| 170 |
"metadata": { |
| 171 |
"interpreter": { |
| 172 |
"hash": "f9c1ad921755d07784f600fc7c2c11a8933ade33898d5981f5e318f268234d48" |
| 173 |
}, |
| 174 |
"kernelspec": { |
| 175 |
"display_name": "Python 3 (ipykernel)", |
| 176 |
"language": "python", |
| 177 |
"name": "python3" |
| 178 |
}, |
| 179 |
"language_info": { |
| 180 |
"codemirror_mode": { |
| 181 |
"name": "ipython", |
| 182 |
"version": 3 |
| 183 |
}, |
| 184 |
"file_extension": ".py", |
| 185 |
"mimetype": "text/x-python", |
| 186 |
"name": "python", |
| 187 |
"nbconvert_exporter": "python", |
| 188 |
"pygments_lexer": "ipython3", |
| 189 |
"version": "3.9.7" |
| 190 |
} |
| 191 |
}, |
| 192 |
"nbformat": 4, |
| 193 |
"nbformat_minor": 2 |
| 194 |
} |