{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import time\n", "import scipy\n", "from scipy import signal\n", "import matplotlib.pyplot as plt\n", "import matplotlib.colors as mpcol\n", "import src.dab_util as du\n", "import src.signal_gen as sg\n", "import src.tcp_sync as ts\n", "import src.dab_tuning_lib as dt\n", "import pandas as pd\n", "from tqdm import tqdm\n", "reload(sg)\n", "reload(du)\n", "reload(dt)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "use_fft=False" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "if use_fft: t1 = ts.UhdSyncMsg(port=47009, packet_size=4*16384, packet_type=\"f\"*16384)\n", "else: t1 = ts.UhdSyncMsg(port=47009, packet_size=4*1, packet_type=\"f\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "import src.SendDictTcp as sdt" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "sender = sdt.SendDictTcp('127.0.0.1', 1112)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "sender.send({\"txgain\":80})\n", "sender.send({\"rxgain\":15})\n", "sender.send({\"a1\":0.8})\n", "sender.send({\"a2\":0.0})\n", "sender.send({\"a3\":0.0})\n", "sender.send({\"a4\":0.0})\n", "sender.send({\"a5\":0.0})\n", "sender.send({\"a6\":0.0})\n", "sender.send({\"a7\":0.0})\n", "sender.send({\"a8\":0.0})" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "t1.has_msg()\n", "t = time.time()\n", "t1.get_msgs(10000)\n", "print( time.time() - t)\n", "t = time.time()\n", "t1.get_msgs(10000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "reload(dt)\n", "sender.send({\"txgain\":81})\n", "sender.send({\"rxgain\":15})\n", "sender.send({\"a1\":0.8})\n", "sender.send({\"a2\":0.0})\n", "sender.send({\"a3\":0.0})\n", "sender.send({\"a4\":0.0})\n", "sender.send({\"a5\":0.0})\n", "sender.send({\"a6\":0.0})\n", "sender.send({\"a7\":0.0})\n", "sender.send({\"a8\":0.0})\n", "t1.has_msg()\n", "np.mean(t1.get_msgs(10000))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "reload(dt)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "def measure_sholders(verbose = False, raw_data=False, std_max=0.025):\n", " for i in range(20):\n", " try:\n", " if verbose: print(\"%d measurement\" % i)\n", " t1.has_msg()\n", " msgs = t1.get_msgs_fft(20000)\n", " #sholders = [dt.calc_signal_sholder_ratio(np.array(msg), 8000000) for msg in msgs]\n", " #sholders = [dt.calc_max_in_freq_range(np.array(msg), 8000000, 1000000, 1900000, debug=False) for msg in msgs]\n", " #sholders = [dt.calc_mean_in_freq_range(np.array(msg), 8000000, 1000000, 1900000, debug=False) for msg in msgs]\n", " sholders = np.array(msgs)\n", " std = np.std(sholders)\n", " mean = np.mean(sholders)\n", " std_perc = std/np.abs(mean)\n", " if verbose == 2:\n", " print( {\"mean\":mean, \"std\":std, \"std_perc\":std_perc})\n", " if std_perc > std_max:\n", " if verbose: print(\"%.4f std/mean\" % (std_perc))\n", " continue\n", " else:\n", " if raw_data: return sholders\n", " else: return np.mean(sholders)\n", " except Exception as e:\n", " print e\n", " raise Exception(\"Variance of measurement to high\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "a = np.array(measure_sholders(verbose=2, std_max=100, raw_data=True)).flatten()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "b = a[a<0.04]\n", "plt.hist(b, bins=100);" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "from tqdm import tqdm_notebook\n", "\n", "sender.send({\"txgain\":83})\n", "sender.send({\"rxgain\":15})\n", "sender.send({\"a1\":0.8})\n", "\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.5, 0.5, num=10)):\n", " for a3 in tqdm_notebook([0]):\n", " for a4 in tqdm_notebook([0]):\n", "#for a2 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", "# for a3 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", "# for a4 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(verbose=0, std_max=100, raw_data=True)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a2.csv\")\n", "print(time.time() - t)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a3 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " for a4 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a3.csv\")\n", "print(time.time() - t)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a3 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a4 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a4.csv\")\n", "print(time.time() - t)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "from tqdm import tqdm_notebook\n", "\n", "sender.send({\"txgain\":81})\n", "sender.send({\"rxgain\":15})\n", "sender.send({\"a1\":0.8})\n", "\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " for a3 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a4 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a2_81.csv\")\n", "print(time.time() - t)\n", "\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a3 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " for a4 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a3_81.csv\")\n", "print(time.time() - t)\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a3 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a4 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a4_81.csv\")\n", "print(time.time() - t)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "from tqdm import tqdm_notebook\n", "\n", "sender.send({\"txgain\":85})\n", "sender.send({\"rxgain\":15})\n", "sender.send({\"a1\":0.8})\n", "\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " for a3 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a4 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a2_85.csv\")\n", "print(time.time() - t)\n", "\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a3 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " for a4 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a3_85.csv\")\n", "print(time.time() - t)\n", "res = []\n", "err = []\n", "t = time.time()\n", "for a2 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a3 in tqdm_notebook(np.linspace(-0.2, 0.2, num=5)):\n", " for a4 in tqdm_notebook(np.linspace(-0.5, 0.5, num=21)):\n", " try:\n", " sender.send({\"a2\":a2})\n", " sender.send({\"a3\":a3})\n", " sender.send({\"a4\":a4})\n", " losses = measure_sholders(raw_data=True, std=0.03)\n", " for i, loss in enumerate(losses):\n", " res.append({\"a2\":a2, \"a3\":a3, \"a4\":a4, \"loss\":loss, \"run\":i})\n", " except Exception as e:\n", " err.append(e)\n", " df = pd.DataFrame(res)\n", " df.to_csv(\"/tmp/sholder_a4_85.csv\")\n", "print(time.time() - t)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "sender.send({\"txgain\":20})\n", "sender.send({\"rxgain\":15})\n", "sender.send({\"a1\":0.1})" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2" } }, "nbformat": 4, "nbformat_minor": 1 }