aboutsummaryrefslogtreecommitdiffstats
path: root/two_tone_tuner.ipynb
diff options
context:
space:
mode:
authorandreas128 <Andreas>2017-01-08 21:13:25 +0000
committerandreas128 <Andreas>2017-01-08 21:13:25 +0000
commitc1200291c9e7bd14613755d9a18a5c7e325d3e54 (patch)
tree5095ff23d2c5758690a0fcb2deb0b753d09f90ae /two_tone_tuner.ipynb
parenta772bc16753dda15b8257fd2001ff273e44ca014 (diff)
downloadODR-StaticPrecorrection-c1200291c9e7bd14613755d9a18a5c7e325d3e54.tar.gz
ODR-StaticPrecorrection-c1200291c9e7bd14613755d9a18a5c7e325d3e54.tar.bz2
ODR-StaticPrecorrection-c1200291c9e7bd14613755d9a18a5c7e325d3e54.zip
Add simple gradient decent to two_toner_tuner.ipynb
Diffstat (limited to 'two_tone_tuner.ipynb')
-rw-r--r--two_tone_tuner.ipynb74
1 files changed, 66 insertions, 8 deletions
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
@@ -78,28 +78,86 @@
"execution_count": null,
"metadata": {},
"outputs": [],
+ "source": []
+ },
+ {
+ "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",
+ " 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"
]
},
{