Commit 6ca1abdd by Christian Rohlfing

- added raw version of primer for complex values

parent 0a43af3a
 { "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Copyright 2019 Institut für Nachrichtentechnik, RWTH Aachen University\n", "%matplotlib notebook\n", "\n", "from ipywidgets import interact, interactive, fixed, interact_manual\n", "import ipywidgets as widgets\n", "\n", "from ient_nb.ient_plots import *\n", "import matplotlib\n", "from matplotlib.patches import ConnectionPatch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " \n", "
\n", "\n", "# Primer Komplexe Zahlen" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$\n", "s(t)\n", "=\n", "\\mathrm{e}^{\\mathrm{j}2\\pi t}\n", "=\n", "\\cos(2\\pi t) + \\mathrm{j}\\sin(2\\pi t)\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t = np.linspace(-2,2,5001)\n", "s = np.exp(2J*np.pi*t)\n", "\n", "# Plot\n", "fig,ax=plt.subplots(); \n", "ax.plot(t, np.real(s), 'rwth', label=r'$\\mathrm{Re}\\{s(t)\\}$'); \n", "ax.plot(t, np.imag(s), 'grun', label=r'$\\mathrm{Im}\\{s(t)\\}$'); \n", "ax.legend(loc='upper right'); ax.set_xlabel(r'$\\rightarrow t$'); ient_axis(ax);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Demo Zeigerdiagramm" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true, "scrolled": false }, "outputs": [], "source": [ "fig,axs=plt.subplots(2,2,figsize=(6, 6)); fig.tight_layout();\n", "@widgets.interact(t0 = widgets.FloatSlider(min=np.min(t), max=np.max(t), step=0.01, value=0, \n", " description='$t_0$:', continuous_update=True),\n", " show_lines = widgets.Checkbox(value=True, description='Zeige Hilfslinien', style=ient_wdgtl_style))\n", "def update_plot(t0, show_lines):\n", " s0 = np.exp(2J*np.pi*t0) # select s(t0)\n", " xyP = (np.real(s0),np.imag(s0)); xyR = (np.real(s0), t0); xyI = (t0,np.imag(s0));\n", " highlight_args = {'color':'rot', 'marker':'o'}; arrow_args = {'width':1,'headlength':10,'headwidth':10,'fc':'rot'}\n", " anno_args = {'color':'rot-50', 'linestyle':'--', 'arrowstyle':\"-\", 'coordsA':'data', 'coordsB':'data'}\n", " if not axs[0,0].lines: # create plots\n", " # Complex number at time t0\n", " ax = axs[0,0]; ient_axis(ax); ax.axis('equal');\n", " an = np.linspace(0, 2 * np.pi, 100); ax.plot(np.cos(an), np.sin(an), 'black-50')\n", " ax.annotate(\"\", xy=(np.real(s0),np.imag(s0)), xytext=(0, 0), arrowprops=arrow_args)\n", " ax.set_xlabel(r'$\\rightarrow \\mathrm{Re}\\{s(t_0)\\}$'); ax.set_ylabel(r'$\\uparrow \\mathrm{Im}\\{s(t_0)\\}$')\n", " \n", " # Imaginary part\n", " ax = axs[0,1]; ax.plot(t, np.imag(s), 'black-50'); ax.plot(t0, np.imag(s0), **highlight_args); ient_axis(ax);\n", " ax.set_xlabel(r'$\\rightarrow t$'); ax.set_ylabel(r'$\\uparrow \\mathrm{Im}\\{s(t)\\}$'); ax.set_zorder(-1)\n", "\n", " # Real part\n", " ax = axs[1,0]; ax.plot(np.real(s),t, 'black-50'); ax.plot(np.real(s0), t0, **highlight_args); ient_axis(ax);\n", " ax.set_ylabel(r'$\\downarrow t$'); ax.set_xlabel(r'$\\rightarrow \\mathrm{Re}\\{s(t)\\}$', bbox=ient_wbbox); \n", " ax.invert_yaxis(); ax.set_zorder(-1)\n", " axs[1,1].set_visible(False); fig.tight_layout(); # hide last axis and tighten layout\n", " else: # update plots\n", " annotations = [child for child in axs[0,0].get_children() if isinstance(child, matplotlib.text.Annotation)]\n", " annotations[0].remove()\n", " axs[0,0].annotate(\"\", xy=(np.real(s0),np.imag(s0)), xytext=(0, 0), arrowprops=arrow_args)\n", " axs[0,1].lines[1].set_xdata(t0); axs[0,1].lines[1].set_ydata(np.imag(s0))\n", " axs[1,0].lines[1].set_ydata(t0); axs[1,0].lines[1].set_xdata(np.real(s0))\n", " annotations = [child for child in axs[0,0].get_children() if isinstance(child, matplotlib.patches.ConnectionPatch)]\n", " if len(annotations): annotations[0].remove(); annotations[1].remove();\n", " if show_lines:\n", " con = ConnectionPatch(xyA=xyP, xyB=xyI, axesA=axs[0,0], axesB=axs[0,1],**anno_args); axs[0,0].add_artist(con)\n", " con = ConnectionPatch(xyA=xyP, xyB=xyR, axesA=axs[0,0], axesB=axs[1,0],**anno_args); axs[0,0].add_artist(con)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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", "*Christian Rohlfing, Übungsbeispiele zur Vorlesung \"Grundgebiete der Elektrotechnik 3 - Signale und Systeme\"*, gehalten von Jens-Rainer Ohm, 2019, Institut für Nachrichtentechnik, RWTH Aachen University." ] } ], "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", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }
 ... ... @@ -38,7 +38,7 @@ " * [Zufallssignale in LTI-Systemen](GDET3%20Zufallssignale%20in%20LTI-Systemen.ipynb)\n", " * [Verteilungs- und Verteilungsdichtefunktion](GDET3%20Verteilungsfunktion.ipynb)\n", " \n", "\n", "Zusätzlich steht ein [Primer](GDET3%20Primer%20Komplexe%20Zahlen.ipynb) zu komplexen Zahlen zur Verfügung.\n", "\n", "## Mitwirkende\n", "\n", ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!