GDET3 RLC-System.ipynb 10 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [],
   "source": [
13
    "# Copyright 2020 Institut für Nachrichtentechnik, RWTH Aachen University\n",
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    "%matplotlib widget\n",
    "\n",
    "from ipywidgets import interact, interactive\n",
    "import ipywidgets as widgets\n",
    "from IPython.display import clear_output, display, HTML\n",
    "\n",
    "import cmath # for sqrt(-1)\n",
    "\n",
    "from ient_nb.ient_plots import *\n",
    "from ient_nb.ient_signals import *\n",
    "\n",
    "plt.close('all')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"inline-block\">\n",
    "    <img src=\"ient_nb/figures/rwth_ient_logo@2x.png\" style=\"float: right;height: 5em;\">\n",
    "</div>\n",
    "\n",
    "# RLC-System"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Es wird folgendes RLC-System betrachtet:\n",
    "\n",
    "![Blockdiagramm](figures/rlc_system_block_diagram.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exemplary values\n",
    "R = 16 # Ohm\n",
    "L = 1.5E-3  # Henry, mH\n",
    "C = 1E-6 # Farad, myF"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Berechnung Laplace-Übertragungsfunktion\n",
    "\n",
    "Die Übertragungsfunktion des Systems kann im Laplace-Bereich mittels Spannungsteiler berechnet werden:\n",
    "\n",
    "$$\n",
    "H(p) \n",
    "= \n",
    "\\frac{U_2(p)}{U_1(p)} \n",
    "= \n",
    "\\frac{1/(Cp)}{R+Lp+1/(Cp)}\n",
    "=\n",
    "\\frac{1}{LCp^2+RCp+1}\n",
    "= \n",
    "\\frac{1/(LC)}{p^2+(R/L)p + 1/(LC)}\n",
    "$$\n",
    "\n",
    "mit $p = \\sigma + \\mathrm{j}\\omega = \\sigma + \\mathrm{j}2 \\pi f$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Laplace transfer function\n",
    "H_laplace = lambda p: 1/(L*C*p**2+R*C*p+1);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Polstellen\n",
98
    "Die zugehörigen Polstellen berechnen sich zu\n",
99
100
101
102
    "\n",
    "$$p_{\\mathrm{P},1,2} = \n",
    "- \\underbrace{\\frac{R}{2L}}_{=a} \\pm \\underbrace{\\sqrt{\\frac{R^2}{4L^2} - \\frac{1}{LC}}}_{=b}\n",
    "$$\n",
Christian Rohlfing's avatar
Christian Rohlfing committed
103
    "mit $a=\\frac{R}{2L}$ und $b=\\sqrt{\\frac{R^2}{4L^2}-\\frac{1}{LC}}$."
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Poles\n",
    "a = R/(2*L)\n",
    "b = cmath.sqrt(R**2/(4*L**2)-1/(L*C))\n",
    "\n",
    "p_p1 = -a+b\n",
    "p_p2 = -a-b\n",
    "\n",
    "# Print out the numbers\n",
    "print(\"a={0:.3f}\".format(a))\n",
    "print(\"b={0:.3f}\".format(b))\n",
    "\n",
    "if R**2/(4*L**2) >= 1/(L*C): print(\"b reell\")\n",
    "else: print(\"b imaginär\")\n",
    "\n",
    "print(\"\\nPolstellen:\")\n",
    "print(\"p_p1={0:.3f}, p_p2={0:.3f}\".format(p_p1, p_p2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
134
135
136
    "### Pol-Nulstellendiagramm\n",
    "Nachfolgend wird das Pol-Nulstellendiagramm geplottet. Es enthält die beiden konjugiert komplexen Polstellen, den Konvergenzbereich und das zugehörige $H_0$. \n",
    "Da der Konvergenzbereich die imaginäre Achse beinhaltet, ist das System stabil. "
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "beta = np.imag(b) # Imaginary part of the poles\n",
    "\n",
    "pp = np.array([p_p1, p_p2]); pz = np.array([]) # Zeros # Poles and Zeros\n",
    "ord_p = np.array([1, 1]); ord_z = np.array([]) # Poles' and Zeros' orders\n",
    "roc = np.array([np.max(np.real(pp)), np.inf]) # region of convergence\n",
    "\n",
    "# Plot\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(np.real(pp), np.imag(pp), **ient_style_poles); ax.plot(np.real(pp), -np.imag(pp), **ient_style_poles); ient_annotate_order(ax, pp, ord_p);\n",
    "ax.plot(np.real(pz), np.imag(pz), **ient_style_zeros); ax.plot(np.real(pz), -np.imag(pz), **ient_style_zeros); ient_annotate_order(ax, pz, ord_z);\n",
    "ient_plot_lroc(ax, roc, 500, np.imag(p_p1)); ax.text(-1000,ax.get_ylim()[1]*0.8,'$H_0 = 1/(LC)$',bbox = ient_wbbox);\n",
    "ax.set_xlim(ax.get_xlim()[0], 300); ient_annotate_xtick(ax, r'$-a$', -a,0,'k');\n",
    "ax.set_xlabel(r'$\\rightarrow \\mathrm{Re}\\{p\\}$'); ax.set_ylabel(r'$\\uparrow \\mathrm{Im}\\{p\\}$'); ient_grid(ax); ient_axis(ax); "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fourier-Übertragungsfunktion\n",
165
    "Aus der Laplaceübertragungsfunktion kann die Fourierübertragungsfunktion berechnet werden, indem $p = \\mathrm{j}2\\pi f$ gesetzt wird:\n",
Christian Rohlfing's avatar
Christian Rohlfing committed
166
    "$$H(p = \\mathrm{j}2\\pi f) \\quad\\text{mit}\\quad \\omega_0 = \\frac{1}{\\sqrt{LC}}$$"
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fourier transfer function\n",
    "H_fourier = lambda f: H_laplace(1j*2*np.pi*f)\n",
    "f = np.linspace(0, 10000, 10000) # frequency axis\n",
    "\n",
    "# Resonance frequency\n",
    "omega0 = 1/np.sqrt(L*C)\n",
    "f0 = omega0/(2*np.pi)\n",
    "\n",
183
184
185
    "# Print f0\n",
    "print(\"f0 = {0:.2f} Hz\".format (f0))\n",
    "\n",
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
    "# Plot\n",
    "fig,ax = plt.subplots()\n",
    "ax.plot(f/1000, np.abs(H_fourier(f))); ient_axis(ax)\n",
    "ax.set_xlabel(r'$\\rightarrow f$ [kHz]'); ax.set_ylabel(r'$\\uparrow |H(f)|$');\n",
    "ient_annotate_xtick(ax, r'$f_0 = \\omega_0/(2\\pi)$', omega0/(2*np.pi)/1000,-0.25,'k');\n",
    "ax.axvline(f0/1000,0,1, color='k',linestyle='--');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Impulsantwort\n",
    "\n",
    "Die Impulsantwort kann mittels Partialbruchzerlegung (siehe Vorlesung) bestimmt werden zu\n",
    "\n",
    "$$\n",
    "h(t) = \\frac{\\mathrm{e}^{-at}}{bLC}\n",
    "\\frac{\\mathrm{e}^{bt}-\\mathrm{e}^{-bt}}{2}\n",
    "\\cdot \\varepsilon(t)\n",
    "$$\n",
    "\n",
208
209
    "mit $a=\\frac{R}{2L}$ und $b=\\sqrt{\\frac{R^2}{4L^2}-\\frac{1}{LC}}$.\n",
    "Der nachfolgende Plot zeigt diese Impulsantwort."
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Impulse response (time-domain)\n",
    "h = lambda t: np.real(np.exp(-a*t)/(b*L*C)*(np.exp(b*t)-np.exp(-b*t))/2*unitstep(t))\n",
    "t = np.linspace(-0.001, 0.01, 10000) # time axis\n",
    "\n",
    "# Plot\n",
    "fig,ax = plt.subplots()\n",
    "ax.plot(t*1000, h(t), 'rwth'); ient_axis(ax); ax.set_xlim([-0.1, 5])\n",
    "ax.set_xlabel(r'$\\rightarrow t$ [ms]'); ax.set_ylabel(r'$\\uparrow h(t)$');\n",
    "#np.mean(np.abs(h(t) - 1/(beta*L*C)*np.exp(-a*t)*np.sin(beta*t)*unitstep(t))**2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interaktive Demo\n",
    "\n",
235
    "In dieser interaktiven Demo kann das Verhalten des Systems für variable Werte von $R$ betrachtet werden. Über den Schieberegler kann der Wert für $R$ geändert werden, entsprechend sieht man die Änderungen für die Fourier-Übertragungsfunktion und die Impulsantwort."
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [],
   "source": [
    "fig0,axs = plt.subplots(2, 1, figsize=(8,16)); fig0.canvas.layout.height= '600px'\n",
    "@widgets.interact(Rsel=widgets.FloatSlider(min=0, max=200, step=1, value=R, description='$R$ [$\\Omega$]'))\n",
    "def update_plot(Rsel):\n",
    "    H_laplace = lambda p: 1/(L*C*p**2+Rsel*C*p+1);\n",
    "    H_fourier = lambda f: H_laplace(1j*2*np.pi*f);\n",
    "    \n",
    "    a = Rsel/(2*L)\n",
    "    b = cmath.sqrt(Rsel**2/(4*L**2)-1/(L*C))\n",
    "    h = lambda t: np.real(np.exp(-a*t)/(b*L*C)*(np.exp(b*t)-np.exp(-b*t))/2*unitstep(t))\n",
    "        \n",
    "    if not axs[0].lines: # Call plot() and decorate axes. Usually, these functions take some processing time\n",
    "        ax = axs[0]; ax.plot(f/1000, np.abs(H_fourier(f))); ient_axis(ax)\n",
    "        ax.set_xlabel(r'$\\rightarrow f$ [kHz]'); ax.set_ylabel(r'$\\uparrow |H(f)|$');\n",
    "        ax.axvline(f0/1000,0,1, color='k',linestyle='--');\n",
    "        \n",
    "        ax = axs[1]; ax.plot(t*1000, h(t), 'rwth'); ient_axis(ax); ax.set_xlim([-.225, 5])\n",
    "        ax.set_xlabel(r'$\\rightarrow t$ [ms]'); ax.set_ylabel(r'$\\uparrow h(t)$');\n",
    "        \n",
    "    else: # If lines exist, replace only xdata and ydata since plt.plot() takes longer time\n",
    "        axs[0].lines[0].set_ydata(np.abs(H_fourier(f)))\n",
    "        axs[1].lines[0].set_ydata(h(t))\n",
    "        \n",
    "    tmp = np.max(np.abs(H_fourier(f))); ient_update_ylim(axs[0], np.abs(H_fourier(f)), 0.1*tmp, tmp+10 )\n",
    "    tmp = np.max(np.abs(h(t))); ient_update_ylim(axs[1], (h(t)), 0.1*tmp, tmp+10 )\n",
    "    display(HTML('{}<br />{}'.format('a={0:.3f}'.format(a), 'b={0:.3f}'.format(b))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
279
    "___\n",
280
281
282
    "This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources) (OER). Feel free to use the notebook for your own purposes. The code is licensed under the [MIT license](https://opensource.org/licenses/MIT). \n",
    "\n",
    "Please attribute the work as follows: \n",
283
    "*Christian Rohlfing, Übungsbeispiele zur Vorlesung \"Grundgebiete der Elektrotechnik 3 - Signale und Systeme\"*, gehalten von Jens-Rainer Ohm, 2020, Institut für Nachrichtentechnik, RWTH Aachen University."
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
303
   "version": "3.8.1"
304
305
306
307
308
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}