From e0936ccdb7a7e0a59eddf580d2f0442672c8931b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20M=C3=BCller?= <muellerl@mv.uni-kl.de>
Date: Tue, 14 Jul 2020 18:12:37 +0200
Subject: [PATCH] added notebook

---
 "\303\234bung 11.ipynb" | 149 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 149 insertions(+)
 create mode 100644 "\303\234bung 11.ipynb"

diff --git "a/\303\234bung 11.ipynb" "b/\303\234bung 11.ipynb"
new file mode 100644
index 0000000..c3ba598
--- /dev/null
+++ "b/\303\234bung 11.ipynb"	
@@ -0,0 +1,149 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# Übung 11 - Abtastung & Aliasing\n",
+    "\n",
+    "In dieser Übung betrachten wir ein Signal $x(t)=\\cos(2\\pi\\cdot f\\cdot t)$ mit der Frequenz $f=10\\,\\text{Hz}$ , welches mit einer Frequenz $f_T$ abgetastet werden soll.\n",
+    "\n",
+    "Um die bei diesem Unterfangen möglicherweise auftretenden Probleme zu visualisieren, setzen wir in diesem Notebook eine variierende Abtastfrequenz $f_T$ ein, die durch einen Slider variiert werden kann.\n",
+    "## Berechnung und Definition"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "from numpy import cos, pi, abs\n",
+    "import numpy\n",
+    "from scipy.fft import fft, fftshift\n",
+    "\n",
+    "\n",
+    "f = 10 # Hz\n",
+    "ft = 40 # Hz\n",
+    "duration = 1 # s\n",
+    "\n",
+    "t = numpy.linspace(0, duration, 5000)\n",
+    "n = numpy.arange(0, duration*ft)\n",
+    "zeropadding = 2**10\n",
+    "Omega = numpy.linspace(-pi, pi, zeropadding)\n",
+    "\n",
+    "def x_continuous(t, f):\n",
+    "    return cos(2*pi*f*t)\n",
+    "\n",
+    "def x_discrete(n, ft):\n",
+    "    return cos(2*pi*f/ft*n)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Visualisierung"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "scrolled": false
+   },
+   "outputs": [],
+   "source": [
+    "from IPython.display import display\n",
+    "from ipywidgets import IntSlider, FloatSlider\n",
+    "from matplotlib import pyplot\n",
+    "%matplotlib notebook\n",
+    "\n",
+    "ft_slider = IntSlider(min=1, max=f*5, layout={'width':'100%'}, value=2)\n",
+    "\n",
+    "figure, (axis1, axis2) = pyplot.subplots(2, 1)\n",
+    "pyplot.tight_layout()\n",
+    "figure.set_figwidth(13)\n",
+    "figure.set_figheight(13)\n",
+    "x_result = x_continuous(t, f)\n",
+    "\n",
+    "def slider_update_plot(changes):\n",
+    "    ft = ft_slider.value # get the sampling frequency from the slider\n",
+    "    n = numpy.arange(0, duration*ft)\n",
+    "    dft = abs(fftshift(fft(x_discrete(n, ft), zeropadding)))/ft/duration\n",
+    "    max_index = numpy.argmax(dft[0:int(zeropadding/2)])\n",
+    "    omega_max = abs(Omega[max_index])\n",
+    "    \n",
+    "    # visualize\n",
+    "    axis1.cla()\n",
+    "    axis1.set_xlim((0, 1))\n",
+    "    axis1.plot(t, x_result)\n",
+    "    axis1.plot(t, x_continuous(t, omega_max*ft/(2*pi)))\n",
+    "    axis1.stem(n/ft, x_discrete(n, ft))\n",
+    "    axis1.set_xlabel('$t$ in s', fontsize=22)\n",
+    "    axis1.set_yticks([-1, 0, 1])\n",
+    "    axis2.cla()\n",
+    "    axis2.set_xlim((-12, 12))\n",
+    "    axis2.set_ylim((0, 1.1))\n",
+    "    axis2.plot(Omega*ft/(2*pi), dft)\n",
+    "    axis2.set_xticks(numpy.arange(-12, 13, 1))\n",
+    "    axis2.set_ylabel('DFT{x[n]}', fontsize=22)\n",
+    "    axis2.set_xlabel('$f$ in Hz', fontsize=22)\n",
+    "\n",
+    "ft_slider.observe(slider_update_plot)\n",
+    "slider_update_plot(None)\n",
+    "display(ft_slider)"
+   ]
+  }
+ ],
+ "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.8.3"
+  },
+  "varInspector": {
+   "cols": {
+    "lenName": 16,
+    "lenType": 16,
+    "lenVar": 40
+   },
+   "kernels_config": {
+    "python": {
+     "delete_cmd_postfix": "",
+     "delete_cmd_prefix": "del ",
+     "library": "var_list.py",
+     "varRefreshCmd": "print(var_dic_list())"
+    },
+    "r": {
+     "delete_cmd_postfix": ") ",
+     "delete_cmd_prefix": "rm(",
+     "library": "var_list.r",
+     "varRefreshCmd": "cat(var_dic_list()) "
+    }
+   },
+   "types_to_exclude": [
+    "module",
+    "function",
+    "builtin_function_or_method",
+    "instance",
+    "_Feature"
+   ],
+   "window_display": false
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
-- 
GitLab