Debian Codegraph @

doc/source/examples/vectorfitting/vectorfitting_ex4_passivity.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Ex4: Passivity Evaluation and Enforcement\n",
8 "To demonstrate the passivity evaluation and enforcement features of the vector fitting class, the ring slot example 2-port is used, once again. Have a look at the other vector fitting example notebooks for more general explanations of the fitting process."
9 ]
10 },
11 {
12 "cell_type": "code",
13 "execution_count": null,
14 "metadata": {},
15 "outputs": [],
16 "source": [
17 "import matplotlib.pyplot as mplt\n",
18 "import numpy as np\n",
19 "\n",
20 "import skrf\n",
21 "\n",
22 "# load and fit the ring slot network with 3 poles\n",
23 "nw = skrf.data.ring_slot\n",
24 "vf = skrf.VectorFitting(nw)\n",
25 "vf.vector_fit(n_poles_real=3, n_poles_cmplx=0)\n",
26 "\n",
27 "# plot fitting results\n",
28 "freqs = np.linspace(0, 200e9, 201)\n",
29 "fig, ax = mplt.subplots(2, 2)\n",
30 "fig.set_size_inches(12, 8)\n",
31 "vf.plot_s_mag(0, 0, freqs=freqs, ax=ax[0][0]) # s11\n",
32 "vf.plot_s_mag(0, 1, freqs=freqs, ax=ax[0][1]) # s12\n",
33 "vf.plot_s_mag(1, 0, freqs=freqs, ax=ax[1][0]) # s21\n",
34 "vf.plot_s_mag(1, 1, freqs=freqs, ax=ax[1][1]) # s22\n",
35 "fig.tight_layout()\n",
36 "mplt.show()"
37 ]
38 },
39 {
40 "cell_type": "markdown",
41 "metadata": {},
42 "source": [
43 "The fitting result looks fine, but a UserWarning about a non-passive vector fit was printed. Before investigating this issue, let's check the RMS error:"
44 ]
45 },
46 {
47 "cell_type": "code",
48 "execution_count": null,
49 "metadata": {},
50 "outputs": [],
51 "source": [
52 "vf.get_rms_error()"
53 ]
54 },
55 {
56 "cell_type": "markdown",
57 "metadata": {},
58 "source": [
59 "An RMS error of less than 0.05 usually indicates a good fit and confirms our optical inspection. But what about the passivity of the fitted model?"
60 ]
61 },
62 {
63 "cell_type": "code",
64 "execution_count": null,
65 "metadata": {},
66 "outputs": [],
67 "source": [
68 "vf.is_passive()"
69 ]
70 },
71 {
72 "cell_type": "markdown",
73 "metadata": {},
74 "source": [
75 "Why is the model not passive? Wasn't the original data of the ring slot representing a passive network?"
76 ]
77 },
78 {
79 "cell_type": "code",
80 "execution_count": null,
81 "metadata": {},
82 "outputs": [],
83 "source": [
84 "nw.is_passive()"
85 ]
86 },
87 {
88 "cell_type": "markdown",
89 "metadata": {},
90 "source": [
91 "The network data was passive, but the vector fitted model is not. Let's investigate (and correct?) the problem some more. "
92 ]
93 },
94 {
95 "cell_type": "code",
96 "execution_count": null,
97 "metadata": {},
98 "outputs": [],
99 "source": [
100 "# plot singular values of vector fitted scattering matrix\n",
101 "freqs = np.linspace(0, 200e9, 201)\n",
102 "fig, ax = mplt.subplots(1, 1)\n",
103 "fig.set_size_inches(6, 4)\n",
104 "vf.plot_s_singular(freqs=freqs, ax=ax)\n",
105 "fig.tight_layout()\n",
106 "mplt.show()"
107 ]
108 },
109 {
110 "cell_type": "markdown",
111 "metadata": {},
112 "source": [
113 "One of the singular values of the fitted scattering matrix is greater than 1 at some frequencies. This indeed indicates a non-passive model. For further analysis, you can get a list of all frequency bands with passivity violations:"
114 ]
115 },
116 {
117 "cell_type": "code",
118 "execution_count": null,
119 "metadata": {},
120 "outputs": [],
121 "source": [
122 "vf.passivity_test()"
123 ]
124 },
125 {
126 "cell_type": "markdown",
127 "metadata": {},
128 "source": [
129 "The network is not passive in two frequency bands: From dc to about 27.8 GHz, and from 84.3 GHz to 98.5 GHz.\n",
130 "Luckily, passivity can be enforced to obtain passive vector fitted model:"
131 ]
132 },
133 {
134 "cell_type": "code",
135 "execution_count": null,
136 "metadata": {},
137 "outputs": [],
138 "source": [
139 "vf.passivity_enforce()"
140 ]
141 },
142 {
143 "cell_type": "markdown",
144 "metadata": {},
145 "source": [
146 "After passivity enforcement, the network should be passive at all frequencies. Let's check ourselves:"
147 ]
148 },
149 {
150 "cell_type": "code",
151 "execution_count": null,
152 "metadata": {},
153 "outputs": [],
154 "source": [
155 "vf.is_passive()"
156 ]
157 },
158 {
159 "cell_type": "code",
160 "execution_count": null,
161 "metadata": {},
162 "outputs": [],
163 "source": [
164 "vf.passivity_test()"
165 ]
166 },
167 {
168 "cell_type": "code",
169 "execution_count": null,
170 "metadata": {},
171 "outputs": [],
172 "source": [
173 "# plot singular values of vector fitted scattering matrix\n",
174 "freqs = np.linspace(0, 200e9, 201)\n",
175 "fig, ax = mplt.subplots(1, 1)\n",
176 "fig.set_size_inches(6, 4)\n",
177 "vf.plot_s_singular(freqs=freqs, ax=ax)\n",
178 "fig.tight_layout()\n",
179 "mplt.show()"
180 ]
181 },
182 {
183 "cell_type": "markdown",
184 "metadata": {},
185 "source": [
186 "Alright, the model is finally passive. But does it still fit the original network data?"
187 ]
188 },
189 {
190 "cell_type": "code",
191 "execution_count": null,
192 "metadata": {},
193 "outputs": [],
194 "source": [
195 "# plot fitting results again after passivity enforcement\n",
196 "freqs = np.linspace(0, 200e9, 201)\n",
197 "fig, ax = mplt.subplots(2, 2)\n",
198 "fig.set_size_inches(12, 8)\n",
199 "vf.plot_s_mag(0, 0, freqs=freqs, ax=ax[0][0]) # s11\n",
200 "vf.plot_s_mag(0, 1, freqs=freqs, ax=ax[0][1]) # s12\n",
201 "vf.plot_s_mag(1, 0, freqs=freqs, ax=ax[1][0]) # s21\n",
202 "vf.plot_s_mag(1, 1, freqs=freqs, ax=ax[1][1]) # s22\n",
203 "fig.tight_layout()\n",
204 "mplt.show()"
205 ]
206 },
207 {
208 "cell_type": "markdown",
209 "metadata": {},
210 "source": [
211 "In addition to the visual inspection, let's check the RMS error again:"
212 ]
213 },
214 {
215 "cell_type": "code",
216 "execution_count": null,
217 "metadata": {},
218 "outputs": [],
219 "source": [
220 "vf.get_rms_error()"
221 ]
222 },
223 {
224 "cell_type": "markdown",
225 "metadata": {},
226 "source": [
227 "Yes, the model still fits the original data very well and the differences to the first non-passive fit from above are insignificant: the rms error is still very low."
228 ]
229 }
230 ],
231 "metadata": {
232 "kernelspec": {
233 "display_name": "Python 3",
234 "language": "python",
235 "name": "python3"
236 },
237 "language_info": {
238 "codemirror_mode": {
239 "name": "ipython",
240 "version": 3
241 },
242 "file_extension": ".py",
243 "mimetype": "text/x-python",
244 "name": "python",
245 "nbconvert_exporter": "python",
246 "pygments_lexer": "ipython3",
247 "version": "3.8.8"
248 }
249 },
250 "nbformat": 4,
251 "nbformat_minor": 4
252 }