| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "markdown", |
| 5 |
"metadata": {}, |
| 6 |
"source": [ |
| 7 |
"# Compute Error Between S Parameter Matrices" |
| 8 |
] |
| 9 |
}, |
| 10 |
{ |
| 11 |
"cell_type": "code", |
| 12 |
"execution_count": null, |
| 13 |
"metadata": {}, |
| 14 |
"outputs": [], |
| 15 |
"source": [ |
| 16 |
"import matplotlib.pyplot as plt\n", |
| 17 |
"import numpy as np\n", |
| 18 |
"\n", |
| 19 |
"import skrf as rf" |
| 20 |
] |
| 21 |
}, |
| 22 |
{ |
| 23 |
"cell_type": "markdown", |
| 24 |
"metadata": {}, |
| 25 |
"source": [ |
| 26 |
"### Load data" |
| 27 |
] |
| 28 |
}, |
| 29 |
{ |
| 30 |
"cell_type": "code", |
| 31 |
"execution_count": null, |
| 32 |
"metadata": {}, |
| 33 |
"outputs": [], |
| 34 |
"source": [ |
| 35 |
"ns = rf.NetworkSet.from_zip(\"LFCN-2352+_S2P.zip\")\n", |
| 36 |
"ns.plot_s_db()\n", |
| 37 |
"plt.legend(loc=\"lower center\", ncols=2, fontsize=\"x-small\")\n", |
| 38 |
"plt.grid()\n", |
| 39 |
"plt.ylim(-40, 0)\n", |
| 40 |
"plt.xlim(0, 50e9)\n", |
| 41 |
"plt.title(\"LFCN-2352+\")" |
| 42 |
] |
| 43 |
}, |
| 44 |
{ |
| 45 |
"cell_type": "markdown", |
| 46 |
"metadata": {}, |
| 47 |
"source": [ |
| 48 |
"### Compute Error and Plot Results" |
| 49 |
] |
| 50 |
}, |
| 51 |
{ |
| 52 |
"cell_type": "code", |
| 53 |
"execution_count": null, |
| 54 |
"metadata": {}, |
| 55 |
"outputs": [], |
| 56 |
"source": [ |
| 57 |
"error_functions = [\n", |
| 58 |
" \"average_l1_norm\",\n", |
| 59 |
" \"average_l2_norm\",\n", |
| 60 |
" \"maximum_l1_norm\",\n", |
| 61 |
" \"average_normalized_l1_norm\",\n", |
| 62 |
"]\n", |
| 63 |
"\n", |
| 64 |
"for ef in error_functions:\n", |
| 65 |
" error = rf.s_error(ntwkA=ns[2], ntwkB=ns[1], error_function=ef)\n", |
| 66 |
" plt.plot(ns[2].frequency.f_scaled, 20 * np.log10(error), label=ef)\n", |
| 67 |
"\n", |
| 68 |
"plt.legend(fontsize=\"small\", ncols=2, loc=\"lower center\")\n", |
| 69 |
"plt.grid()\n", |
| 70 |
"plt.ylim(-50, 0)\n", |
| 71 |
"plt.xlim(0, 50000)\n", |
| 72 |
"plt.title(f\"Error Between {ns[2].name} and {ns[1].name}\", fontsize=\"small\")\n", |
| 73 |
"plt.xlabel(\"Frequency (MHz)\")" |
| 74 |
] |
| 75 |
} |
| 76 |
], |
| 77 |
"metadata": { |
| 78 |
"kernelspec": { |
| 79 |
"display_name": ".venv", |
| 80 |
"language": "python", |
| 81 |
"name": "python3" |
| 82 |
}, |
| 83 |
"language_info": { |
| 84 |
"codemirror_mode": { |
| 85 |
"name": "ipython", |
| 86 |
"version": 3 |
| 87 |
}, |
| 88 |
"file_extension": ".py", |
| 89 |
"mimetype": "text/x-python", |
| 90 |
"name": "python", |
| 91 |
"nbconvert_exporter": "python", |
| 92 |
"pygments_lexer": "ipython3", |
| 93 |
"version": "3.9.13" |
| 94 |
} |
| 95 |
}, |
| 96 |
"nbformat": 4, |
| 97 |
"nbformat_minor": 2 |
| 98 |
} |