aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore12
-rw-r--r--live_analyse.grc2
-rw-r--r--live_analyse_py.grc252
-rw-r--r--src/tcp_async.py (renamed from tcp_async.py)0
-rw-r--r--src/tcp_sync.py (renamed from tcp_sync.py)0
-rw-r--r--src/two_tone_lib.py75
-rw-r--r--two_tone_tuner.ipynb197
7 files changed, 289 insertions, 249 deletions
diff --git a/.gitignore b/.gitignore
index cbdc681..0eb1cf3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,18 @@ top_block.py
Untitled.ipynb
Untitled.py
Untitled.txt
+Untitled1.ipynb
+Untitled1.py
+Untitled1.txt
+input.dat
+input.dat.png
+input.dat_fft.png
+live_analyse_py.py
+myplot.pickle
+run.py
+run.txt
+two_tone_tuner.py
+
diff --git a/live_analyse.grc b/live_analyse.grc
index 737798e..ff33842 100644
--- a/live_analyse.grc
+++ b/live_analyse.grc
@@ -461,7 +461,7 @@
</param>
<param>
<key>file</key>
- <value>/home/andreas/dab/dab_normalized_c64.dat</value>
+ <value>/home/andreas/dab/ODR-StaticPrecorrection/input.dat</value>
</param>
<param>
<key>_coordinate</key>
diff --git a/live_analyse_py.grc b/live_analyse_py.grc
index b380b70..f24bcab 100644
--- a/live_analyse_py.grc
+++ b/live_analyse_py.grc
@@ -244,53 +244,6 @@
</param>
</block>
<block>
- <key>analog_const_source_x</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>const</key>
- <value>0</value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(896, 76)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>analog_const_source_x_0</value>
- </param>
- <param>
- <key>maxoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>minoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>type</key>
- <value>complex</value>
- </param>
- </block>
- <block>
<key>blks2_tcp_sink</key>
<param>
<key>addr</key>
@@ -365,7 +318,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1240, 343)</value>
+ <value>(800, 343)</value>
</param>
<param>
<key>_rotation</key>
@@ -393,57 +346,6 @@
</param>
</block>
<block>
- <key>blocks_add_xx</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(1112, 121)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_add_xx_1</value>
- </param>
- <param>
- <key>type</key>
- <value>complex</value>
- </param>
- <param>
- <key>maxoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>minoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>num_inputs</key>
- <value>2</value>
- </param>
- <param>
- <key>vlen</key>
- <value>1</value>
- </param>
- </block>
- <block>
<key>blocks_file_source</key>
<param>
<key>alias</key>
@@ -546,128 +448,6 @@
</param>
</block>
<block>
- <key>blocks_multiply_const_vxx</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>const</key>
- <value>1</value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(784, 148)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_multiply_const_vxx_1</value>
- </param>
- <param>
- <key>type</key>
- <value>complex</value>
- </param>
- <param>
- <key>maxoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>minoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>vlen</key>
- <value>1</value>
- </param>
- </block>
- <block>
- <key>dpd_memless_poly</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(576, 99)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>dpd_memless_poly_0</value>
- </param>
- <param>
- <key>maxoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>minoutbuf</key>
- <value>0</value>
- </param>
- <param>
- <key>a1</key>
- <value>1</value>
- </param>
- <param>
- <key>a2</key>
- <value>0</value>
- </param>
- <param>
- <key>a3</key>
- <value>0</value>
- </param>
- <param>
- <key>a4</key>
- <value>0</value>
- </param>
- <param>
- <key>a5</key>
- <value>0</value>
- </param>
- <param>
- <key>a6</key>
- <value>0</value>
- </param>
- <param>
- <key>a7</key>
- <value>0</value>
- </param>
- <param>
- <key>a8</key>
- <value>0</value>
- </param>
- </block>
- <block>
<key>logpwrfft_x</key>
<param>
<key>avg_alpha</key>
@@ -703,7 +483,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(848, 329)</value>
+ <value>(568, 329)</value>
</param>
<param>
<key>_rotation</key>
@@ -1449,7 +1229,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1232, 95)</value>
+ <value>(704, 111)</value>
</param>
<param>
<key>_rotation</key>
@@ -2676,20 +2456,8 @@
</param>
</block>
<connection>
- <source_block_id>analog_const_source_x_0</source_block_id>
- <sink_block_id>blocks_add_xx_1</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_add_xx_1</source_block_id>
- <sink_block_id>uhd_usrp_sink_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
<source_block_id>blocks_file_source_0</source_block_id>
- <sink_block_id>dpd_memless_poly_0</sink_block_id>
+ <sink_block_id>uhd_usrp_sink_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
</connection>
@@ -2700,18 +2468,6 @@
<sink_key>0</sink_key>
</connection>
<connection>
- <source_block_id>blocks_multiply_const_vxx_1</source_block_id>
- <sink_block_id>blocks_add_xx_1</sink_block_id>
- <source_key>0</source_key>
- <sink_key>1</sink_key>
- </connection>
- <connection>
- <source_block_id>dpd_memless_poly_0</source_block_id>
- <sink_block_id>blocks_multiply_const_vxx_1</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
<source_block_id>logpwrfft_x_0</source_block_id>
<sink_block_id>blks2_tcp_sink_1_0</sink_block_id>
<source_key>0</source_key>
diff --git a/tcp_async.py b/src/tcp_async.py
index 05cadd7..05cadd7 100644
--- a/tcp_async.py
+++ b/src/tcp_async.py
diff --git a/tcp_sync.py b/src/tcp_sync.py
index 6a2e619..6a2e619 100644
--- a/tcp_sync.py
+++ b/src/tcp_sync.py
diff --git a/src/two_tone_lib.py b/src/two_tone_lib.py
new file mode 100644
index 0000000..df7d53f
--- /dev/null
+++ b/src/two_tone_lib.py
@@ -0,0 +1,75 @@
+import numpy as np
+import matplotlib.pyplot as plt
+
+def gen_two_tone(path = "./input.dat", predist = None, par = None, debug = False):
+ period1 = 3.875
+ period2 = 4
+ t_both = 124
+ assert(t_both / period1 % 1 == 0)
+ assert(t_both / period2 % 1 == 0)
+
+ t = np.arange(0,t_both)
+ sin1 = np.sin(t * 2 * np.pi * 1./period1)
+ sin2 = np.sin(t * 2 * np.pi * 1./period2)
+ sig = sin1 + sin2
+
+ if predist is None:
+ res = sig
+ else:
+ res = predist(sig, par)
+
+ res = res / np.max(res)
+
+ res = res.astype(np.complex64)
+ res.tofile(path)
+
+ a_load = np.fromfile(path, dtype=np.complex64)
+ assert(np.isclose(a_load, res).all()), "Inconsistent stored file"
+
+ if debug == True:
+ plt.plot(np.abs(np.concatenate((a_load, a_load))))
+ plt.savefig(path + ".png")
+ plt.clf()
+
+ plt.plot(np.abs(np.fft.fftshift(np.fft.fft(np.concatenate((a_load, a_load))))), 'ro')
+ plt.savefig(path + "_fft.png")
+ plt.clf()
+
+ return path
+
+def predist_poly(sig, coefs = []):
+ res = sig
+ for idx, coef in enumerate(coefs):
+ res += sig * np.abs(sig)**(idx+1) * coef #+1 because first correction term is squared
+ return res
+
+def analyse_power_spec(spec, debug = False, debug_path="", suffix=""):
+ peak_1 = None
+ peak_2 = None
+ spec_start = 4096
+ spec_end = 8192
+ first_peak = spec_start + 2048
+ second_peak = spec_start + 2114
+ delta_freq = 66
+ peak_other = []
+ if debug: plt.plot(spec[spec_start:spec_end])
+ for x in [c * delta_freq + delta_freq//2 for c in range(spec_start//delta_freq)]:
+ start = spec_start + x
+ end = spec_start + x + delta_freq
+ peak = spec[start:end].max()
+ if debug: plt.plot((start-spec_start,end-spec_start), (peak, peak))
+ if start < first_peak and end > first_peak:
+ peak_1 = peak
+ if debug: plt.plot((start-spec_start,end-spec_start), (peak+1, peak+1))
+ elif start < second_peak and end > second_peak:
+ peak_2 = peak
+ if debug: plt.plot((start-spec_start,end-spec_start), (peak+1, peak+1))
+ else:
+ peak_other.append(peak)
+ mean_signal = (peak_1 + peak_2) / 2
+ mean_others = np.mean(peak_other)
+ score = mean_signal - mean_others
+ if debug:
+ plt.savefig(debug_path + "/" + str(score) + suffix + ".png")
+ plt.clf()
+ return score
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
+}