{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "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", "import src.dab_tuning_lib as dt\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": { "deletable": true, "editable": true }, "outputs": [], "source": [ "try:\n", " __IPYTHON__\n", " reload(tcp_async)\n", " reload(tcp_sync)\n", " reload(gen_source)\n", " reload(tt)\n", " reload(td)\n", "except:\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "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": { "deletable": true, "editable": true }, "outputs": [], "source": [ "top = live_analyse_py()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "top.start()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "sync.has_msg()\n", "async.has_msg()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "top.set_txgain(85)\n", "top.set_rxgain(15)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "tt.gen_two_tone(debug = True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "a = np.fromfile(\"./input.dat\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a.max()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "def measure(param, debug = False):\n", " #x2, x3, x4, x5, x6, x7, x8 = param\n", " x1, x2, x3, x4, x5, x6, x7, x8 = param + [1]\n", " \n", " repeat = True\n", " while repeat:\n", " #tt.gen_two_tone(debug = True, predist=tt.predist_poly, par=(x2, x3, x4))\n", " \n", " #top.dpd_memless_poly_0.set_a1(0.8)\n", " #top.dpd_memless_poly_0.set_a2(x2)\n", " #top.dpd_memless_poly_0.set_a3(x3)\n", " #top.dpd_memless_poly_0.set_a4(x4)\n", " #top.dpd_memless_poly_0.set_a5(x5)\n", " #top.dpd_memless_poly_0.set_a6(x6)\n", " #top.dpd_memless_poly_0.set_a7(x7)\n", " #top.dpd_memless_poly_0.set_a8(x8)\n", " \n", " top.dpd_lut_0.set_a1(x1)\n", " top.dpd_lut_0.set_a2(x2)\n", " top.dpd_lut_0.set_a3(x3)\n", " top.dpd_lut_0.set_a4(x4)\n", " top.dpd_lut_0.set_a5(x5)\n", " top.dpd_lut_0.set_a6(x6)\n", " top.dpd_lut_0.set_a7(x7)\n", " top.dpd_lut_0.set_a8(1)\n", " \n", " sync.has_msg()\n", " np.array(sync.get_msgs(3))\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", " print (\"repeat due to async message\")\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_%.3fx_5_%.3fx_6_%.3fx_7_%.3fx_8_%.3f\" % \\\n", " (x2, x3, x4, x5, x6, x7, x8)\n", " sig_to_noise = tt.analyse_power_spec(mean_msg, debug=debug, debug_path=\"/tmp/out\", suffix=suffix)\n", " #sig_to_noise = dt.calc_signal_sholder_ratio(mean_msg, sampling_rate=8000000, debug=debug, debug_path=\"/tmp/out\", suffix=suffix)\n", " print(sig_to_noise, x2, x3, x4, x5, x6, x7, x8)\n", " repeat = False\n", " \n", " return sig_to_noise" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "def simple_opt(pars, i, d, func):\n", " par = pars[i]\n", " test_pars = []\n", " for x in [-3, -2, -1, 0, 1, 2, 3]:\n", " debug = x == 0\n", " new_par = list(pars)\n", " new_par[i] = par + x * d \n", " test_pars.append([new_par, debug])\n", " res = [func(par_new, debug) for par_new, debug in test_pars]\n", " sel = np.argmax(res)\n", " best_par = zip(*test_pars)[0][sel]\n", " return best_par\n", "\n", "#pars = [1,1,1]\n", "#i_rand = np.random.randint(0, len(pars))\n", "#pars = simple_opt(pars, i_rand, 0.01, lambda x:np.sum(x))\n", "#pars" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": true, "editable": true }, "outputs": [], "source": [ "#top.blocks_file_source_0.open(\"../dab_normalized_c64.dat\", True)" ] }, { "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": [ "reload(dt)\n", "top.set_txgain(84)\n", "top.set_rxgain(5)\n", "\n", "pars = np.array(range(1,8))/8.\n", "\n", "for i in range(10000):\n", " i_rand = np.random.randint(0, len(pars))\n", " pars = simple_opt(pars, i_rand, 0.05, measure)" ] }, { "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": [ "sync.stop()\n", "async.stop()\n", "top.stop()\n", "top.wait()" ] }, { "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": [] }, { "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 }