From c1200291c9e7bd14613755d9a18a5c7e325d3e54 Mon Sep 17 00:00:00 2001 From: andreas128 Date: Sun, 8 Jan 2017 21:13:25 +0000 Subject: Add simple gradient decent to two_toner_tuner.ipynb --- gr-dpd/grc/dpd_memless_poly.xml | 7 + gr-dpd/include/dpd/memless_poly.h | 7 + live_analyse.grc | 1004 +++++++++++++++++++++++++++++++++---- live_analyse_py.grc | 81 ++- run.ipynb | 4 +- two_tone_tuner.ipynb | 74 ++- 6 files changed, 1078 insertions(+), 99 deletions(-) diff --git a/gr-dpd/grc/dpd_memless_poly.xml b/gr-dpd/grc/dpd_memless_poly.xml index ce687a7..98871a1 100644 --- a/gr-dpd/grc/dpd_memless_poly.xml +++ b/gr-dpd/grc/dpd_memless_poly.xml @@ -22,36 +22,43 @@ a2 a2 + 0 real a3 a3 + 0 real a4 a4 + 0 real a5 a5 + 0 real a6 a6 + 0 real a7 a7 + 0 real a8 a8 + 0 real diff --git a/gr-dpd/include/dpd/memless_poly.h b/gr-dpd/include/dpd/memless_poly.h index 921a9df..a3d17d2 100644 --- a/gr-dpd/include/dpd/memless_poly.h +++ b/gr-dpd/include/dpd/memless_poly.h @@ -48,7 +48,14 @@ namespace gr { */ static sptr make(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8); + virtual void set_a1(float sens) = 0; virtual void set_a2(float sens) = 0; + virtual void set_a3(float sens) = 0; + virtual void set_a4(float sens) = 0; + virtual void set_a5(float sens) = 0; + virtual void set_a6(float sens) = 0; + virtual void set_a7(float sens) = 0; + virtual void set_a8(float sens) = 0; }; diff --git a/live_analyse.grc b/live_analyse.grc index 5483676..04bedef 100644 --- a/live_analyse.grc +++ b/live_analyse.grc @@ -674,7 +674,7 @@ value - 20 + 40 _enabled @@ -827,7 +827,7 @@ value - 20 + 80 _enabled @@ -882,6 +882,49 @@ counter_slider + + blocks_complex_to_real + + alias + + + + comment + + + + affinity + + + + _enabled + 0 + + + _coordinate + (656, 241) + + + _rotation + 0 + + + id + blocks_complex_to_real_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + vlen + 1 + + blocks_file_source @@ -1083,11 +1126,15 @@ - dpd_memless_poly + blocks_null_sink alias + + bus_conns + [[0,],] + comment @@ -1100,6 +1147,49 @@ _enabled True + + _coordinate + (712, 289) + + + _rotation + 0 + + + id + blocks_null_sink_0_2_0 + + + type + complex + + + num_inputs + 1 + + + vlen + 1 + + + + dpd_memless_poly + + alias + + + + comment + + + + affinity + + + + _enabled + 1 + _coordinate (512, 27) @@ -1122,59 +1212,621 @@ a1 - 1 + a_1 a2 a_2 - a3 - a_3 + a3 + a_3 + + + a4 + a_4 + + + a5 + a_5 + + + a6 + a_6 + + + a7 + a_7 + + + a8 + a_8 + + + + qtgui_freq_sink_x + + autoscale + False + + + average + 1.0 + + + bw + samp_rate + + + alias + + + + fc + 0 + + + comment + + + + ctrlpanel + False + + + affinity + + + + _enabled + 1 + + + fftsize + 16000 + + + _coordinate + (712, 142) + + + gui_hint + + + + _rotation + 0 + + + grid + False + + + id + qtgui_freq_sink_x_0_0 + + + legend + True + + + alpha1 + 1.0 + + + color1 + "blue" + + + label1 + + + + width1 + 1 + + + alpha10 + 1.0 + + + color10 + "dark blue" + + + label10 + + + + width10 + 1 + + + alpha2 + 1.0 + + + color2 + "red" + + + label2 + + + + width2 + 1 + + + alpha3 + 1.0 + + + color3 + "green" + + + label3 + + + + width3 + 1 + + + alpha4 + 1.0 + + + color4 + "black" + + + label4 + + + + width4 + 1 + + + alpha5 + 1.0 + + + color5 + "cyan" + + + label5 + + + + width5 + 1 + + + alpha6 + 1.0 + + + color6 + "magenta" + + + label6 + + + + width6 + 1 + + + alpha7 + 1.0 + + + color7 + "yellow" + + + label7 + + + + width7 + 1 + + + alpha8 + 1.0 + + + color8 + "dark red" + + + label8 + + + + width8 + 1 + + + alpha9 + 1.0 + + + color9 + "dark green" + + + label9 + + + + width9 + 1 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + name + "" + + + nconnections + 1 + + + showports + True + + + freqhalf + True + + + tr_chan + 0 + + + tr_level + 0.0 + + + tr_mode + qtgui.TRIG_MODE_FREE + + + tr_tag + "" + + + type + complex + + + update_time + 0.25 + + + wintype + firdes.WIN_BLACKMAN_hARRIS + + + ymax + 10 + + + ymin + -140 + + + + qtgui_freq_sink_x + + autoscale + False + + + average + 1.0 + + + bw + samp_rate + + + alias + + + + fc + 0 + + + comment + + + + ctrlpanel + False + + + affinity + + + + _enabled + 0 + + + fftsize + 16000 + + + _coordinate + (1056, 22) + + + gui_hint + + + + _rotation + 0 + + + grid + False + + + id + qtgui_freq_sink_x_0_0_0 + + + legend + True + + + alpha1 + 1.0 + + + color1 + "blue" + + + label1 + + + + width1 + 1 + + + alpha10 + 1.0 + + + color10 + "dark blue" + + + label10 + + + + width10 + 1 + + + alpha2 + 1.0 + + + color2 + "red" + + + label2 + + + + width2 + 1 + + + alpha3 + 1.0 + + + color3 + "green" + + + label3 + + + + width3 + 1 + + + alpha4 + 1.0 + + + color4 + "black" + + + label4 + + + + width4 + 1 + + + alpha5 + 1.0 + + + color5 + "cyan" + + + label5 + + + + width5 + 1 + + + alpha6 + 1.0 + + + color6 + "magenta" + + + label6 + + + + width6 + 1 + + + alpha7 + 1.0 + + + color7 + "yellow" + + + label7 + + + + width7 + 1 + + + alpha8 + 1.0 + + + color8 + "dark red" + + + label8 + + + + width8 + 1 + + + alpha9 + 1.0 + + + color9 + "dark green" + + + label9 + + + + width9 + 1 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + name + "" + + + nconnections + 1 + + + showports + True + + + freqhalf + True + + + tr_chan + 0 + + + tr_level + 0.0 + + + tr_mode + qtgui.TRIG_MODE_FREE + + + tr_tag + "" - a4 - a_4 + type + complex - a5 - a_5 + update_time + 0.10 - a6 - a_6 + wintype + firdes.WIN_BLACKMAN_hARRIS - a7 - a_7 + ymax + 10 - a8 - a_8 + ymin + -140 - qtgui_freq_sink_x + qtgui_time_sink_x autoscale False - - average - 1.0 - - - bw - samp_rate - alias - - fc - 0 - comment @@ -1188,16 +1840,16 @@ - _enabled + entags True - fftsize - 16000 + _enabled + 0 _coordinate - (704, 222) + (1056, 102) gui_hint @@ -1213,7 +1865,7 @@ id - qtgui_freq_sink_x_0_0 + qtgui_time_sink_x_0 legend @@ -1231,6 +1883,14 @@ label1 + + marker1 + -1 + + + style1 + 1 + width1 1 @@ -1241,12 +1901,20 @@ color10 - "dark blue" + "blue" label10 + + marker10 + -1 + + + style10 + 1 + width10 1 @@ -1263,6 +1931,14 @@ label2 + + marker2 + -1 + + + style2 + 1 + width2 1 @@ -1279,6 +1955,14 @@ label3 + + marker3 + -1 + + + style3 + 1 + width3 1 @@ -1295,6 +1979,14 @@ label4 + + marker4 + -1 + + + style4 + 1 + width4 1 @@ -1311,6 +2003,14 @@ label5 + + marker5 + -1 + + + style5 + 1 + width5 1 @@ -1327,6 +2027,14 @@ label6 + + marker6 + -1 + + + style6 + 1 + width6 1 @@ -1343,6 +2051,14 @@ label7 + + marker7 + -1 + + + style7 + 1 + width7 1 @@ -1359,6 +2075,14 @@ label8 + + marker8 + -1 + + + style8 + 1 + width8 1 @@ -1376,16 +2100,16 @@ - width9 - 1 + marker9 + -1 - maxoutbuf - 0 + style9 + 1 - minoutbuf - 0 + width9 + 1 name @@ -1396,17 +2120,21 @@ 1 - showports - True + size + 1024 - freqhalf - True + srate + samp_rate tr_chan 0 + + tr_delay + 0 + tr_level 0.0 @@ -1415,6 +2143,10 @@ tr_mode qtgui.TRIG_MODE_FREE + + tr_slope + qtgui.TRIG_SLOPE_POS + tr_tag "" @@ -1425,43 +2157,35 @@ update_time - 0.1 + 0.10 - wintype - firdes.WIN_BLACKMAN_hARRIS + ylabel + Amplitude + + + yunit + "" ymax - 10 + 1 ymin - -140 + -1 - qtgui_freq_sink_x + qtgui_time_sink_x autoscale False - - average - 1.0 - - - bw - samp_rate - alias - - fc - 0 - comment @@ -1475,16 +2199,16 @@ - _enabled + entags True - fftsize - 16000 + _enabled + 0 _coordinate - (1056, 38) + (848, 222) gui_hint @@ -1500,7 +2224,7 @@ id - qtgui_freq_sink_x_0_0_0 + qtgui_time_sink_x_0_0 legend @@ -1518,6 +2242,14 @@ label1 + + marker1 + -1 + + + style1 + 1 + width1 1 @@ -1528,12 +2260,20 @@ color10 - "dark blue" + "blue" label10 + + marker10 + -1 + + + style10 + 1 + width10 1 @@ -1550,6 +2290,14 @@ label2 + + marker2 + -1 + + + style2 + 1 + width2 1 @@ -1566,6 +2314,14 @@ label3 + + marker3 + -1 + + + style3 + 1 + width3 1 @@ -1582,6 +2338,14 @@ label4 + + marker4 + -1 + + + style4 + 1 + width4 1 @@ -1598,6 +2362,14 @@ label5 + + marker5 + -1 + + + style5 + 1 + width5 1 @@ -1614,6 +2386,14 @@ label6 + + marker6 + -1 + + + style6 + 1 + width6 1 @@ -1630,6 +2410,14 @@ label7 + + marker7 + -1 + + + style7 + 1 + width7 1 @@ -1646,6 +2434,14 @@ label8 + + marker8 + -1 + + + style8 + 1 + width8 1 @@ -1663,16 +2459,16 @@ - width9 - 1 + marker9 + -1 - maxoutbuf - 0 + style9 + 1 - minoutbuf - 0 + width9 + 1 name @@ -1683,17 +2479,21 @@ 1 - showports - True + size + 1024 - freqhalf - True + srate + samp_rate tr_chan 0 + + tr_delay + 0 + tr_level 0.0 @@ -1702,29 +2502,37 @@ tr_mode qtgui.TRIG_MODE_FREE + + tr_slope + qtgui.TRIG_SLOPE_POS + tr_tag "" type - complex + float update_time 0.10 - wintype - firdes.WIN_BLACKMAN_hARRIS + ylabel + Amplitude + + + yunit + "" ymax - 10 + 1 ymin - -140 + -1 @@ -2442,7 +3250,7 @@ _coordinate - (1056, 119) + (1056, 199) _rotation @@ -3513,7 +4321,7 @@ _enabled - True + 1 _coordinate @@ -3668,6 +4476,12 @@ + + blocks_complex_to_real_0 + qtgui_time_sink_x_0_0 + 0 + 0 + blocks_file_source_0 dpd_memless_poly_0 @@ -3686,6 +4500,12 @@ 0 0 + + blocks_multiply_const_vxx_1 + qtgui_time_sink_x_0 + 0 + 0 + blocks_multiply_const_vxx_1 uhd_usrp_sink_0 @@ -3704,6 +4524,18 @@ msg msg + + uhd_usrp_source_0 + blocks_complex_to_real_0 + 0 + 0 + + + uhd_usrp_source_0 + blocks_null_sink_0_2_0 + 0 + 0 + uhd_usrp_source_0 qtgui_freq_sink_x_0_0 diff --git a/live_analyse_py.grc b/live_analyse_py.grc index f24bcab..907de4c 100644 --- a/live_analyse_py.grc +++ b/live_analyse_py.grc @@ -369,7 +369,7 @@ _coordinate - (312, 141) + (192, 133) _rotation @@ -447,6 +447,77 @@ 1 + + dpd_memless_poly + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (480, 99) + + + _rotation + 0 + + + id + dpd_memless_poly_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + a1 + 1 + + + a2 + 0 + + + a3 + 0 + + + a4 + 0 + + + a5 + 0 + + + a6 + 0 + + + a7 + 0 + + + a8 + 0 + + logpwrfft_x @@ -2457,7 +2528,7 @@ blocks_file_source_0 - uhd_usrp_sink_0 + dpd_memless_poly_0 0 0 @@ -2467,6 +2538,12 @@ 0 0 + + dpd_memless_poly_0 + uhd_usrp_sink_0 + 0 + 0 + logpwrfft_x_0 blks2_tcp_sink_1_0 diff --git a/run.ipynb b/run.ipynb index 2a1c78b..0bc3e84 100644 --- a/run.ipynb +++ b/run.ipynb @@ -112,9 +112,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "top." - ] + "source": [] }, { "cell_type": "code", diff --git a/two_tone_tuner.ipynb b/two_tone_tuner.ipynb index 0272401..2b4d5d9 100644 --- a/two_tone_tuner.ipynb +++ b/two_tone_tuner.ipynb @@ -73,6 +73,13 @@ "sync.has_msg()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -80,26 +87,77 @@ "outputs": [], "source": [ "def measure(param):\n", - " x2 = param[0]\n", - " x3 = param[1]\n", - " x4 = param[2]\n", + " x2, x3, x4, x5, x6, x7, x8 = param\n", + " \n", " repeat = True\n", " while repeat:\n", - " tt.gen_two_tone(debug = True, predist=tt.predist_poly, par=(x2, x3, x4))\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", " sync.has_msg()\n", - " np.array(sync.get_msgs(2))\n", + " np.array(sync.get_msgs(1))\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_%.3f\" % (x2, x3, x4)\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=True, debug_path=\"/tmp/out\", suffix=suffix)\n", - " print(sig_to_noise, x2, x3, x4)\n", - " repeat = False" + " 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": {}, + "outputs": [], + "source": [ + "def simple_opt(pars, i, d, func):\n", + " par = pars[i]\n", + " test_pars = []\n", + " for x in [-1, 0, 1]:\n", + " new_par = list(pars)\n", + " new_par[i] = par + x * d \n", + " test_pars.append(new_par)\n", + " res = [func(par_new) for par_new in test_pars]\n", + " sel = np.argmax(res)\n", + " best_par = test_pars[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": {}, + "outputs": [], + "source": [ + "top.set_txgain(85)\n", + "pars = np.zeros(7)\n", + "\n", + "for i in range(100):\n", + " i_rand = np.random.randint(0, len(pars))\n", + " pars = simple_opt(pars, i_rand, 0.05, measure)\n" ] }, { -- cgit v1.2.3