m-thesis-introduction/simulations/03_emitter_receiver_simulation.ipynb

296 lines
36 KiB
Text
Raw Normal View History

2022-03-07 18:34:26 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Emitter/Receiver Simulation with Signals"
]
},
{
"cell_type": "code",
2022-03-10 14:59:35 +01:00
"execution_count": 1,
2022-03-07 18:34:26 +01:00
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
2022-03-10 14:59:35 +01:00
"from functools import partial\n",
2022-03-07 18:34:26 +01:00
"\n",
2022-03-10 14:59:35 +01:00
"import matplotlib.pyplot as plt"
2022-03-07 18:34:26 +01:00
]
},
2022-03-10 14:59:35 +01:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
2022-03-07 18:34:26 +01:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Signal"
]
},
{
"cell_type": "code",
2022-03-10 14:59:35 +01:00
"execution_count": 2,
2022-03-07 18:34:26 +01:00
"metadata": {},
"outputs": [],
"source": [
2022-03-10 14:59:35 +01:00
"from lib.TravelSignal import TravelSignal\n",
2022-03-07 18:34:26 +01:00
"\n",
2022-03-10 14:59:35 +01:00
"####\n",
"from scipy.stats import norm\n",
2022-03-07 18:34:26 +01:00
"\n",
2022-03-10 14:59:35 +01:00
"sample_rate = 3e2 # Hz\n",
"interp_sample_rate = sample_rate * 1/10 # Hz\n",
"\n",
"t_offset = 8\n",
"periodic = False\n",
"\n",
"time = t_offset + np.arange(0, 1, 1/sample_rate) #s\n",
"time2 = t_offset + np.arange(-1.5, 1, 1/sample_rate) #s\n",
"\n",
"signal = norm.pdf(time, time[len(time)//2], (time[-1] - time[0])/10)\n",
"\n",
"if False:\n",
" mysignal = TravelSignal(signal, sample_rate, t_0 = t_offset, periodic=True)\n",
" mysignal2 = TravelSignal(signal, sample_rate, t_0 = t_offset, periodic=False)\n",
"\n",
" fig, ax = plt.subplots(1, 1, figsize=(16,4))\n",
" ax.set_title(\"Raw and TravelSignal\")\n",
" ax.set_ylabel(\"Amplitude\")\n",
" ax.set_xlabel(\"Time\")\n",
"\n",
" ax.plot(time, signal, label='Raw signal')\n",
" ax.plot(time2, mysignal(time2)+0.5, '.-', label='TravelSignal(periodic)+0.5')\n",
" ax.plot(time2, mysignal2(time2)-0.5, '.-', label='TravelSignal-0.5')\n",
"\n",
" ax.legend()\n",
"\n",
" plt.show();"
2022-03-07 18:34:26 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## New code"
]
},
{
"cell_type": "code",
2022-03-10 14:59:35 +01:00
"execution_count": 3,
2022-03-07 18:34:26 +01:00
"metadata": {},
"outputs": [],
"source": [
"### Location\n",
"class Location:\n",
" \"\"\"\n",
" A location is a point designated by a spatial coordinate x.\n",
" \"\"\"\n",
"\n",
" def __init__(self, x):\n",
" self.x = np.asarray(x) \n",
"\n",
" def __repr__(self):\n",
" return \"Location({})\".format(repr(self.x))\n",
"\n",
" def __getitem__(self, key):\n",
" return self.x[key]\n",
"\n",
" def __setitem__(self, key, val):\n",
" self.x[key] = val\n",
"\n",
" def __add__(self, other):\n",
2022-03-10 14:59:35 +01:00
" if isinstance(other, Location):\n",
2022-03-07 18:34:26 +01:00
" other = other.x\n",
"\n",
" return self.__class__(self.x + other)\n",
"\n",
" def __sub__(self, other):\n",
2022-03-10 14:59:35 +01:00
" if isinstance(other, Location):\n",
2022-03-07 18:34:26 +01:00
" other = other.x\n",
"\n",
" return self.__class__(self.x - other)\n",
" \n",
" def __eq__(self, other):\n",
2022-03-10 14:59:35 +01:00
" if isinstance(other, Location):\n",
2022-03-07 18:34:26 +01:00
" other = other.x\n",
"\n",
" return np.all(self.x == other)"
]
},
{
"cell_type": "code",
2022-03-10 14:59:35 +01:00
"execution_count": 4,
2022-03-07 18:34:26 +01:00
"metadata": {},
"outputs": [],
"source": [
"### Receiver\n",
"class Receiver(Location):\n",
" \"\"\"\n",
2022-03-10 14:59:35 +01:00
" A location able to trace a signal over time.\n",
" \n",
" Optionally applies a transformation to the traced signal.\n",
2022-03-07 18:34:26 +01:00
" \"\"\"\n",
2022-03-10 14:59:35 +01:00
" def __repr__(self):\n",
" return \"Receiver({})\".format(repr(self.x))\n",
" \n",
" def recv(self, travel_signal: TravelSignal) -> TravelSignal:\n",
" \"\"\"\n",
" Return a function that traces the signal as a function of time\n",
" at the receiver's location\n",
" \"\"\"\n",
" return partial(travel_signal, x_f=self.x) "
2022-03-07 18:34:26 +01:00
]
},
{
"cell_type": "code",
2022-03-10 14:59:35 +01:00
"execution_count": 5,
2022-03-07 18:34:26 +01:00
"metadata": {},
"outputs": [],
"source": [
" ### Emitter\n",
2022-03-10 14:59:35 +01:00
"class Emitter(Location):\n",
2022-03-07 18:34:26 +01:00
" \"\"\"\n",
" Emit a signal from position x_0 (and time t_0)\n",
" \"\"\"\n",
2022-03-10 14:59:35 +01:00
" def emit(self, travel_signal: TravelSignal) -> TravelSignal:\n",
" return partial(travel_signal, x_0=self.x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Testing"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPIAAACqCAYAAACXtRI+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAQuklEQVR4nO3dfbRVdZ3H8fcHEVAkynhIVCBdpqIktUgrZ1KzHNEpnFU2miU5FqmZzZpaiY3NOGOm0zRrKpXMykkzdFyrYaLGHkwzKx9hYkxERsYQCIGLSmIqBnznj9/vxu54z72Xyz133/Pj81rrrnP2w9n7ux8+e//2Pufco4jAzNrbkLoLMLOd5yCbFcBBNiuAg2xWAAfZrAAOslkBHOSdIOlgSb+UtEnSBS2e16ckfa2V88jzGS7pYUmv6mG810q6u9X1VOb3AUk/H6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ADrJZARxkswI4yGYFcJDNCuAgmxXAQTYrgINsVgAH2awADrJZARxkswI4yGYFaOtfY+yOpBXAJmArsGVX/yFsK1uxQc6Oi4gNdRdh1mpuWpsVoOQgB/AjSYskza67GLNWKrlpfXRErJE0DrhN0iMRcVfnwBzu2QATJ06sq0azflHsGTki1uTH9cB84MiG4ddGxPSImD527Ng6SjTrN0UGWdJISaM6nwMnAA/VW5VZ65TatB4PzJcEaRnnRcQP6i3JrHWKDHJEPAYcUXcdZgOlyKa12a7GQTYrgINsVgAH2awAfQqypEslfazSfZmkC/qvLDPbEX09I38dmAUgaQh
"text/plain": [
"<Figure size 144x144 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAvEAAAF1CAYAAABh8bWyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdeZhcZ3nn/e+t7la3pO6WbUleZVk2NjE2IQYLE15lsQ1J2MIyIcRmCUzCZTIZxhjDEAjJYCZAhkmGEPslMBrgzcJiglkCOMCw2MOYgEHyho1ZjBcsb1otdUvqbrX6fv84p6RSq6rX6q5q1fdzXbq66pznnLqrTkv69dP3OScyE0mSJEkLx6JmFyBJkiRpegzxkiRJ0gJjiJckSZIWGEO8JEmStMAY4iVJkqQFxhAvSZIkLTCGeEk6CkTE0oi4PiJ2RcQn5/i1LoyIu+byNeZaRNwUEa9pdh2SNFOGeEltKSIGq/6MRcS+quevaHZ9M/B7wHHAisy8dPzKiHhXROwf9763zeSFMvPGzDy3at+bI+LCqudnRsSCvwlJRLw2IjIi/t00t/tYRFw1R2VJEmCIl9SmMrO38gf4OfDbVcs+Pn58RHTOf5XTchrw48wcnWDMx6vfd2aunK/ipqOFPutXAz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V6y6MiP9ntvVJml8DQ/sPttP0H5yJN8RLktRInQ3Yx77MPG8mG2bmw8BLy6fnAeuAfy2fXwgMAv821f1FRGdmmhakJhoYGj0Y3g/1xNtOI0lSI81ZO01E3B8R74mI70TExoh4WkR8NSJ+FhF/VI5ZGxF3RsRi4L8Cv1fO5v8J8EfAG8vnvxoRqyLiMxHx/fLP+nI
"text/plain": [
"<Figure size 864x432 with 4 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"if True:\n",
" sample_rate = 3e2 # Hz\n",
" periodic = False\n",
" \n",
" t_offset = 8\n",
" t_start = 0\n",
" t_end = 1\n",
" time = t_offset + np.arange(t_start, t_end, 1/sample_rate) #s\n",
" \n",
" t_longstart = 0\n",
" t_longend = 30*t_end\n",
" longtime = np.arange(t_longstart, t_longend, 1/sample_rate) #s\n",
"\n",
"if False:\n",
" if True:\n",
" freq = sample_rate/8\n",
" signal = np.cos(2*np.pi*freq*time)\n",
" else: \n",
" from scipy.stats import norm\n",
" signal = norm.pdf(time, time[len(time)//2], (time[-1] - time[0])/10)\n",
"\n",
"\n",
"#####\n",
"# Setup Signal, Emitter and Antennae\n",
"\n",
"mysignal = TravelSignal(signal, sample_rate, t_0 = t_offset, periodic=periodic)\n",
"\n",
"source = Emitter([1,1])\n",
"emitted = source.emit(mysignal)\n",
"\n",
"antennae = [\n",
" Receiver([2,3]),\n",
" Receiver([10,10]),\n",
" Receiver([-2,-3]),\n",
"]\n",
" \n",
"#####\n",
"# Follow traces, and show geometry\n",
"ylabel_kw = {\"rotation\": \"horizontal\", \"va\":\"center\", \"ha\":\"center\", \"labelpad\": 30}\n",
"\n",
"fig, axs = plt.subplots(1,1, figsize=(2,2))\n",
"axs = [ axs ]\n",
"\n",
"### Geometry Plot\n",
"i = 0\n",
"axs[i].set_title(\"Geometry of Emitter(s) and Antennae\")\n",
"axs[i].set_ylabel(\"y\", **ylabel_kw)\n",
"axs[i].set_xlabel(\"x\")\n",
"axs[i].plot(*source.x, '*', label=\"Emitter\")\n",
"\n",
"for j, ant in enumerate(antennae):\n",
" axs[i].plot(*ant.x, '+', label=\"Antenna {}\".format(j))\n",
"\n",
"### Plot Traces\n",
"fig, axs = plt.subplots(1+len(antennae),1, sharex=True, figsize=(12,6))\n",
"axs[0].set_title(\"Traces of Emitter and Antenna\")\n",
"\n",
"# Emitter\n",
"i = 0\n",
"axs[i].set_ylabel(\"Emitter\\n at ({},{})\".format(*source.x), **ylabel_kw)\n",
"axs[i].plot(time, emitted(time))\n",
"\n",
"# Antenna\n",
"for j, ant in enumerate(antennae):\n",
" i +=1\n",
" axs[i].set_ylabel(\"Antenna {}\\n at ({},{})\".format(j, *ant.x), **ylabel_kw)\n",
" axs[i].plot(longtime, ant.recv(emitted)(longtime), label=\"Antenna {}\".format(j))\n",
" "
2022-03-07 18:34:26 +01:00
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}