aboutsummaryrefslogtreecommitdiffstats
path: root/two_tone_tuner.ipynb
diff options
context:
space:
mode:
authorandreas128 <Andreas>2017-01-08 14:59:52 +0000
committerandreas128 <Andreas>2017-01-08 14:59:52 +0000
commit059eb97446a52b346a550d12f47478fc978b6001 (patch)
tree18590699a3291d3809de9420718a5872122fd0e9 /two_tone_tuner.ipynb
parent770048b409f7ba0636abc74cecc8efaeb863afb4 (diff)
downloadODR-StaticPrecorrection-059eb97446a52b346a550d12f47478fc978b6001.tar.gz
ODR-StaticPrecorrection-059eb97446a52b346a550d12f47478fc978b6001.tar.bz2
ODR-StaticPrecorrection-059eb97446a52b346a550d12f47478fc978b6001.zip
Add two_tone_lib and tested two_tone_tuner
Diffstat (limited to 'two_tone_tuner.ipynb')
-rw-r--r--two_tone_tuner.ipynb197
1 files changed, 197 insertions, 0 deletions
diff --git a/two_tone_tuner.ipynb b/two_tone_tuner.ipynb
new file mode 100644
index 0000000..0272401
--- /dev/null
+++ b/two_tone_tuner.ipynb
@@ -0,0 +1,197 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%matplotlib inline\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np\n",
+ "import time\n",
+ "import src.gen_source as gen_source\n",
+ "import src.two_tone_lib as tt\n",
+ "\n",
+ "import src.tcp_async as tcp_async\n",
+ "import src.tcp_sync as tcp_sync\n",
+ "\n",
+ "from live_analyse_py import live_analyse_py"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "try:\n",
+ " __IPYTHON__\n",
+ " reload(tcp_async)\n",
+ " reload(tcp_sync)\n",
+ " reload(gen_source)\n",
+ " reload(tt)\n",
+ "except:\n",
+ " pass"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "sync = tcp_sync.UhdSyncMsg(packet_size=4*8192,\n",
+ " packet_type=\"\".join([\"f\"]*8192))\n",
+ "async = tcp_async.UhdAsyncMsg()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "top = live_analyse_py()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "top.start()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "sync.has_msg()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def measure(param):\n",
+ " x2 = param[0]\n",
+ " x3 = param[1]\n",
+ " x4 = param[2]\n",
+ " repeat = True\n",
+ " while repeat:\n",
+ " tt.gen_two_tone(debug = True, predist=tt.predist_poly, par=(x2, x3, x4))\n",
+ " sync.has_msg()\n",
+ " np.array(sync.get_msgs(2))\n",
+ " msgs = np.array(sync.get_msgs(5))\n",
+ " msgs = [np.fft.fftshift(msg) for msg in msgs]\n",
+ " \n",
+ " if async.has_msg():\n",
+ " continue\n",
+ " \n",
+ " a = np.array(msgs)\n",
+ " mean_msg = a.mean(axis = 0)\n",
+ " suffix = \"x_2_%.3f_x_3_%.3f_x_4_%.3f\" % (x2, x3, x4)\n",
+ " sig_to_noise = tt.analyse_power_spec(mean_msg, debug=True, debug_path=\"/tmp/out\", suffix=suffix)\n",
+ " print(sig_to_noise, x2, x3, x4)\n",
+ " repeat = False"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "top.set_txgain(85)\n",
+ "\n",
+ "params = []\n",
+ "for x2 in np.linspace(-0.1, 0.1, num = 11):\n",
+ " for x3 in np.linspace(-0.1, 0.1, num = 11):\n",
+ " for x4 in np.linspace(-0.1, 0.1, num = 11):\n",
+ " params.append((x2, x3, x4))\n",
+ " \n",
+ "t_start = time.time()\n",
+ "for idx, param in enumerate(params):\n",
+ " measure(param)\n",
+ " time_per_element = (time.time() - t_start) / (idx + 1)\n",
+ " print (\"Time per Element \" + str(time_per_element) +\n",
+ " \", total: \" + str(time_per_element * len(params)),\n",
+ " \", left: \" + str(time_per_element * (len(params) - 1 - idx))\n",
+ " )"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "sync.stop()\n",
+ "async.stop()\n",
+ "top.stop()\n",
+ "top.wait()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "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
+}