aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandreas128 <Andreas>2016-12-09 09:38:33 +0100
committerandreas128 <Andreas>2016-12-09 09:38:33 +0100
commitbf1dcd15c041b73aeca73cd1aebe894d3128b4f2 (patch)
tree5714b5995198c7e55c8f11678f27249f8c335a79
parentf2b7d99828e9a9f9d849661a9e24280bbb78f30d (diff)
downloadODR-StaticPrecorrection-bf1dcd15c041b73aeca73cd1aebe894d3128b4f2.tar.gz
ODR-StaticPrecorrection-bf1dcd15c041b73aeca73cd1aebe894d3128b4f2.tar.bz2
ODR-StaticPrecorrection-bf1dcd15c041b73aeca73cd1aebe894d3128b4f2.zip
Add grid search in run.ipynb
-rw-r--r--.gitignore13
-rw-r--r--generate_compensated_2_tone_file.ipynb291
-rw-r--r--live_analyse.grc964
-rw-r--r--run.ipynb254
-rw-r--r--src/__init__.py0
-rw-r--r--src/gen_source.py32
-rw-r--r--tcp_async.py2
-rw-r--r--tcp_sync.py34
8 files changed, 488 insertions, 1102 deletions
diff --git a/.gitignore b/.gitignore
index 54b9753..9c37b59 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,19 @@ tcp_async.pyc
usrp_rx
usrp_tx
lut_generator.py
+generate_compensated_2_tone_file.py
+np_twotone
+np_twotone_dpd
+out_cos
+out_sin
+tcp_sync.pyc
+tmp.grc
+top_block.py
+Untitled.ipynb
+Untitled.py
+Untitled.txt
+
+
diff --git a/generate_compensated_2_tone_file.ipynb b/generate_compensated_2_tone_file.ipynb
deleted file mode 100644
index 7037d3b..0000000
--- a/generate_compensated_2_tone_file.ipynb
+++ /dev/null
@@ -1,291 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "%matplotlib inline\n",
- "import matplotlib.pyplot as plt\n",
- "import numpy as np"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "a = np.fromfile(\"./out_sin\", np.complex64)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "a.shape"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "a = a[0:100]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "mag = np.abs(a)\n",
- "plt.plot(mag)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.plot(a.imag[0:100])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.plot(a.real[0:100])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "def complex_exp(freq, samp_rate, periods, phase_deg=0):\n",
- " t_max = 1.0 * samp_rate / freq * periods\n",
- " t = np.arange(t_max)\n",
- " fac = t / samp_rate * freq\n",
- " phase = 1j * phase_deg/360*2*np.pi\n",
- " ret = np.exp(phase + 1j * 2 * np.pi * fac - 1j * np.pi / 2, dtype=np.complex64)\n",
- " return ret\n",
- "ret = complex_exp(10,40,2)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "samp_rate = 4000000 #samples / second\n",
- "frequency_0 = samp_rate/9. #cycles / second\n",
- "frequency_1 = samp_rate/10. #cycles / second\n",
- "tone_0 = complex_exp(frequency_0, samp_rate, 10, 180)\n",
- "tone_1 = complex_exp(frequency_1, samp_rate, 9)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "def complex_exp(freq, samp_rate, periods):\n",
- " t_max = 1.0 * samp_rate / freq * periods\n",
- " t = np.arange(t_max)\n",
- " fac = t / samp_rate * freq\n",
- " ret = np.exp(1j * 2 * np.pi * fac - 1j * np.pi / 2)\n",
- " return ret\n",
- "ret = complex_exp(10,40,2)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "two_tone = 1/2.0 * (tone_0 + tone_1)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "two_tone[-1]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "two_tone.tofile(\"./np_twotone\")\n",
- "two_tone.dtype"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "a_load = np.fromfile(\"./np_twotone\", dtype=np.complex64)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.plot(a_load.real[0:100])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "import pickle"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "lut_dict = pickle.load(open(\"./lut_tab.pkl\", \"rb\"))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "def dpd(x):\n",
- " mag = np.abs(x)\n",
- " fac = np.interp(mag/2.0, lut_dict[\"ampl\"], lut_dict[\"fac\"])\n",
- " ret = x*fac\n",
- " return ret.astype(np.complex64)\n",
- "\n",
- "#def dpd(x):\n",
- "# return x*0.5"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "tone_0_dpd = np.apply_along_axis(dpd, 0, tone_0)\n",
- "tone_1_dpd = np.apply_along_axis(dpd, 0, tone_1)\n",
- "two_tone_dpd = 1/2. * (tone_0_dpd + tone_1_dpd)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.plot(two_tone_dpd.real[0:200])\n",
- "plt.plot(two_tone.real[0:200])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "two_tone_dpd.tofile(\"./np_twotone\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "two_tone.tofile(\"./np_twotone\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "a_load = np.fromfile(\"./np_twotone_dpd\", dtype=np.complex64)\n",
- "plt.plot(a_load.real[0:200])"
- ]
- },
- {
- "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
-}
diff --git a/live_analyse.grc b/live_analyse.grc
index 550df5c..5b3db4b 100644
--- a/live_analyse.grc
+++ b/live_analyse.grc
@@ -170,7 +170,7 @@
</param>
<param>
<key>value</key>
- <value>0</value>
+ <value>2000000</value>
</param>
<param>
<key>_enabled</key>
@@ -178,7 +178,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(408, 545)</value>
+ <value>(336, 568)</value>
</param>
<param>
<key>gui_hint</key>
@@ -190,76 +190,13 @@
</param>
<param>
<key>id</key>
- <value>pow1</value>
+ <value>high</value>
</param>
<param>
<key>label</key>
- <value>pow1</value>
- </param>
- <param>
- <key>min_len</key>
- <value>200</value>
- </param>
- <param>
- <key>orient</key>
- <value>Qt.Horizontal</value>
- </param>
- <param>
- <key>start</key>
- <value>0</value>
- </param>
- <param>
- <key>step</key>
- <value>0.05</value>
- </param>
- <param>
- <key>stop</key>
- <value>1</value>
- </param>
- <param>
- <key>rangeType</key>
- <value>float</value>
- </param>
- <param>
- <key>widget</key>
- <value>counter_slider</value>
- </param>
- </block>
- <block>
- <key>variable_qtgui_range</key>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>value</key>
- <value>0</value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(288, 545)</value>
- </param>
- <param>
- <key>gui_hint</key>
<value></value>
</param>
<param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>pow2</value>
- </param>
- <param>
- <key>label</key>
- <value>pow2</value>
- </param>
- <param>
<key>min_len</key>
<value>200</value>
</param>
@@ -269,15 +206,15 @@
</param>
<param>
<key>start</key>
- <value>-1</value>
+ <value>50000</value>
</param>
<param>
<key>step</key>
- <value>0.05</value>
+ <value>1</value>
</param>
<param>
<key>stop</key>
- <value>1</value>
+ <value>2000000</value>
</param>
<param>
<key>rangeType</key>
@@ -296,7 +233,7 @@
</param>
<param>
<key>value</key>
- <value>0</value>
+ <value>50000</value>
</param>
<param>
<key>_enabled</key>
@@ -304,7 +241,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(168, 545)</value>
+ <value>(168, 568)</value>
</param>
<param>
<key>gui_hint</key>
@@ -316,11 +253,11 @@
</param>
<param>
<key>id</key>
- <value>pow3</value>
+ <value>low</value>
</param>
<param>
<key>label</key>
- <value>pow3</value>
+ <value></value>
</param>
<param>
<key>min_len</key>
@@ -332,15 +269,15 @@
</param>
<param>
<key>start</key>
- <value>-1</value>
+ <value>50000</value>
</param>
<param>
<key>step</key>
- <value>0.05</value>
+ <value>1</value>
</param>
<param>
<key>stop</key>
- <value>1</value>
+ <value>2000000</value>
</param>
<param>
<key>rangeType</key>
@@ -649,22 +586,14 @@
</param>
</block>
<block>
- <key>analog_const_source_x</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
+ <key>variable_qtgui_range</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
- <key>const</key>
- <value>0</value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
+ <key>value</key>
+ <value>500</value>
</param>
<param>
<key>_enabled</key>
@@ -672,7 +601,11 @@
</param>
<param>
<key>_coordinate</key>
- <value>(488, 108)</value>
+ <value>(168, 688)</value>
+ </param>
+ <param>
+ <key>gui_hint</key>
+ <value></value>
</param>
<param>
<key>_rotation</key>
@@ -680,23 +613,43 @@
</param>
<param>
<key>id</key>
- <value>analog_const_source_x_0</value>
+ <value>width</value>
</param>
<param>
- <key>maxoutbuf</key>
- <value>0</value>
+ <key>label</key>
+ <value></value>
</param>
<param>
- <key>minoutbuf</key>
- <value>0</value>
+ <key>min_len</key>
+ <value>200</value>
</param>
<param>
- <key>type</key>
+ <key>orient</key>
+ <value>Qt.Horizontal</value>
+ </param>
+ <param>
+ <key>start</key>
+ <value>1</value>
+ </param>
+ <param>
+ <key>step</key>
+ <value>1</value>
+ </param>
+ <param>
+ <key>stop</key>
+ <value>5000000</value>
+ </param>
+ <param>
+ <key>rangeType</key>
<value>float</value>
</param>
+ <param>
+ <key>widget</key>
+ <value>counter_slider</value>
+ </param>
</block>
<block>
- <key>blocks_add_xx</key>
+ <key>analog_const_source_x</key>
<param>
<key>alias</key>
<value></value>
@@ -706,6 +659,10 @@
<value></value>
</param>
<param>
+ <key>const</key>
+ <value>0</value>
+ </param>
+ <param>
<key>affinity</key>
<value></value>
</param>
@@ -715,7 +672,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(680, 249)</value>
+ <value>(512, 92)</value>
</param>
<param>
<key>_rotation</key>
@@ -723,11 +680,7 @@
</param>
<param>
<key>id</key>
- <value>blocks_add_xx_0</value>
- </param>
- <param>
- <key>type</key>
- <value>complex</value>
+ <value>analog_const_source_x_0</value>
</param>
<param>
<key>maxoutbuf</key>
@@ -738,12 +691,8 @@
<value>0</value>
</param>
<param>
- <key>num_inputs</key>
- <value>2</value>
- </param>
- <param>
- <key>vlen</key>
- <value>1</value>
+ <key>type</key>
+ <value>complex</value>
</param>
</block>
<block>
@@ -766,7 +715,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(680, 329)</value>
+ <value>(696, 121)</value>
</param>
<param>
<key>_rotation</key>
@@ -817,7 +766,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(960, 553)</value>
+ <value>(968, 321)</value>
</param>
<param>
<key>_rotation</key>
@@ -841,7 +790,7 @@
</param>
</block>
<block>
- <key>blocks_complex_to_mag</key>
+ <key>blocks_complex_to_mag_squared</key>
<param>
<key>alias</key>
<value></value>
@@ -860,7 +809,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(488, 65)</value>
+ <value>(800, 225)</value>
</param>
<param>
<key>_rotation</key>
@@ -868,7 +817,7 @@
</param>
<param>
<key>id</key>
- <value>blocks_complex_to_mag_0</value>
+ <value>blocks_complex_to_mag_squared_0</value>
</param>
<param>
<key>maxoutbuf</key>
@@ -899,11 +848,11 @@
</param>
<param>
<key>_enabled</key>
- <value>True</value>
+ <value>1</value>
</param>
<param>
<key>_coordinate</key>
- <value>(784, 433)</value>
+ <value>(792, 401)</value>
</param>
<param>
<key>_rotation</key>
@@ -911,7 +860,7 @@
</param>
<param>
<key>id</key>
- <value>blocks_complex_to_mag_squared_0</value>
+ <value>blocks_complex_to_mag_squared_0_0</value>
</param>
<param>
<key>maxoutbuf</key>
@@ -927,7 +876,11 @@
</param>
</block>
<block>
- <key>blocks_complex_to_mag_squared</key>
+ <key>blocks_file_sink</key>
+ <param>
+ <key>append</key>
+ <value>False</value>
+ </param>
<param>
<key>alias</key>
<value></value>
@@ -942,11 +895,15 @@
</param>
<param>
<key>_enabled</key>
- <value>1</value>
+ <value>True</value>
+ </param>
+ <param>
+ <key>file</key>
+ <value>fft_sink</value>
</param>
<param>
<key>_coordinate</key>
- <value>(784, 633)</value>
+ <value>(1312, 599)</value>
</param>
<param>
<key>_rotation</key>
@@ -954,19 +911,19 @@
</param>
<param>
<key>id</key>
- <value>blocks_complex_to_mag_squared_0_0</value>
+ <value>blocks_file_sink_0</value>
</param>
<param>
- <key>maxoutbuf</key>
- <value>0</value>
+ <key>type</key>
+ <value>float</value>
</param>
<param>
- <key>minoutbuf</key>
- <value>0</value>
+ <key>unbuffered</key>
+ <value>False</value>
</param>
<param>
<key>vlen</key>
- <value>1</value>
+ <value>8192</value>
</param>
</block>
<block>
@@ -993,7 +950,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(208, 53)</value>
+ <value>(344, 141)</value>
</param>
<param>
<key>_rotation</key>
@@ -1025,49 +982,6 @@
</param>
</block>
<block>
- <key>blocks_float_to_complex</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>(784, 73)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_float_to_complex_0</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>blocks_message_burst_source</key>
<param>
<key>alias</key>
@@ -1087,7 +1001,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(784, 897)</value>
+ <value>(896, 785)</value>
</param>
<param>
<key>_rotation</key>
@@ -1134,7 +1048,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1160, 534)</value>
+ <value>(1168, 302)</value>
</param>
<param>
<key>_rotation</key>
@@ -1189,7 +1103,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(960, 414)</value>
+ <value>(976, 206)</value>
</param>
<param>
<key>_rotation</key>
@@ -1244,7 +1158,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1160, 614)</value>
+ <value>(1168, 382)</value>
</param>
<param>
<key>_rotation</key>
@@ -1299,7 +1213,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(784, 537)</value>
+ <value>(792, 305)</value>
</param>
<param>
<key>_rotation</key>
@@ -1334,59 +1248,8 @@
</param>
<param>
<key>const</key>
- <value>pow3</value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(512, 252)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_multiply_const_vxx_0</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>blocks_multiply_const_vxx</key>
- <param>
- <key>alias</key>
- <value></value>
- </param>
- <param>
- <key>comment</key>
- <value></value>
- </param>
- <param>
- <key>const</key>
- <value>pow1</value>
- </param>
<param>
<key>affinity</key>
<value></value>
@@ -1397,7 +1260,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(528, 356)</value>
+ <value>(536, 148)</value>
</param>
<param>
<key>_rotation</key>
@@ -1425,159 +1288,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>pow2</value>
- </param>
- <param>
- <key>affinity</key>
- <value></value>
- </param>
- <param>
- <key>_enabled</key>
- <value>True</value>
- </param>
- <param>
- <key>_coordinate</key>
- <value>(528, 308)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_multiply_const_vxx_2</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>blocks_multiply_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>(1008, 81)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_multiply_xx_0</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_multiply_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>(1160, 73)</value>
- </param>
- <param>
- <key>_rotation</key>
- <value>0</value>
- </param>
- <param>
- <key>id</key>
- <value>blocks_multiply_xx_0_0</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_null_sink</key>
<param>
<key>alias</key>
@@ -1601,7 +1311,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1368, 433)</value>
+ <value>(1384, 225)</value>
</param>
<param>
<key>_rotation</key>
@@ -1648,7 +1358,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1544, 553)</value>
+ <value>(1552, 321)</value>
</param>
<param>
<key>_rotation</key>
@@ -1695,7 +1405,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1544, 633)</value>
+ <value>(1552, 401)</value>
</param>
<param>
<key>_rotation</key>
@@ -1742,7 +1452,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1208, 897)</value>
+ <value>(1320, 785)</value>
</param>
<param>
<key>_rotation</key>
@@ -1789,7 +1499,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1320, 541)</value>
+ <value>(1328, 309)</value>
</param>
<param>
<key>_rotation</key>
@@ -1844,7 +1554,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1120, 421)</value>
+ <value>(1136, 213)</value>
</param>
<param>
<key>_rotation</key>
@@ -1899,7 +1609,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(1320, 621)</value>
+ <value>(1328, 389)</value>
</param>
<param>
<key>_rotation</key>
@@ -1931,36 +1641,24 @@
</param>
</block>
<block>
- <key>qtgui_freq_sink_x</key>
+ <key>logpwrfft_x</key>
<param>
- <key>autoscale</key>
- <value>False</value>
- </param>
- <param>
- <key>average</key>
+ <key>avg_alpha</key>
<value>1.0</value>
</param>
<param>
- <key>bw</key>
- <value>samp_rate/decimate</value>
+ <key>average</key>
+ <value>False</value>
</param>
<param>
<key>alias</key>
<value></value>
</param>
<param>
- <key>fc</key>
- <value>0</value>
- </param>
- <param>
<key>comment</key>
<value></value>
</param>
<param>
- <key>ctrlpanel</key>
- <value>False</value>
- </param>
- <param>
<key>affinity</key>
<value></value>
</param>
@@ -1969,192 +1667,28 @@
<value>True</value>
</param>
<param>
- <key>fftsize</key>
- <value>16383</value>
+ <key>fft_size</key>
+ <value>8192</value>
</param>
<param>
- <key>_coordinate</key>
- <value>(976, 774)</value>
+ <key>frame_rate</key>
+ <value>30</value>
</param>
<param>
- <key>gui_hint</key>
- <value></value>
+ <key>_coordinate</key>
+ <value>(1048, 585)</value>
</param>
<param>
<key>_rotation</key>
<value>0</value>
</param>
<param>
- <key>grid</key>
- <value>False</value>
- </param>
- <param>
<key>id</key>
- <value>qtgui_freq_sink_x_0_0</value>
- </param>
- <param>
- <key>legend</key>
- <value>True</value>
- </param>
- <param>
- <key>alpha1</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color1</key>
- <value>"blue"</value>
- </param>
- <param>
- <key>label1</key>
- <value></value>
- </param>
- <param>
- <key>width1</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha10</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color10</key>
- <value>"dark blue"</value>
- </param>
- <param>
- <key>label10</key>
- <value></value>
- </param>
- <param>
- <key>width10</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha2</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color2</key>
- <value>"red"</value>
- </param>
- <param>
- <key>label2</key>
- <value></value>
- </param>
- <param>
- <key>width2</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha3</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color3</key>
- <value>"green"</value>
- </param>
- <param>
- <key>label3</key>
- <value></value>
- </param>
- <param>
- <key>width3</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha4</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color4</key>
- <value>"black"</value>
- </param>
- <param>
- <key>label4</key>
- <value></value>
- </param>
- <param>
- <key>width4</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha5</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color5</key>
- <value>"cyan"</value>
- </param>
- <param>
- <key>label5</key>
- <value></value>
- </param>
- <param>
- <key>width5</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha6</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color6</key>
- <value>"magenta"</value>
- </param>
- <param>
- <key>label6</key>
- <value></value>
- </param>
- <param>
- <key>width6</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha7</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color7</key>
- <value>"yellow"</value>
+ <value>logpwrfft_x_0</value>
</param>
<param>
- <key>label7</key>
- <value></value>
- </param>
- <param>
- <key>width7</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha8</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color8</key>
- <value>"dark red"</value>
- </param>
- <param>
- <key>label8</key>
- <value></value>
- </param>
- <param>
- <key>width8</key>
- <value>1</value>
- </param>
- <param>
- <key>alpha9</key>
- <value>1.0</value>
- </param>
- <param>
- <key>color9</key>
- <value>"dark green"</value>
- </param>
- <param>
- <key>label9</key>
- <value></value>
- </param>
- <param>
- <key>width9</key>
- <value>1</value>
+ <key>type</key>
+ <value>complex</value>
</param>
<param>
<key>maxoutbuf</key>
@@ -2165,69 +1699,37 @@
<value>0</value>
</param>
<param>
- <key>name</key>
- <value>""</value>
- </param>
- <param>
- <key>nconnections</key>
- <value>1</value>
- </param>
- <param>
- <key>showports</key>
- <value>True</value>
- </param>
- <param>
- <key>freqhalf</key>
- <value>True</value>
- </param>
- <param>
- <key>tr_chan</key>
- <value>0</value>
- </param>
- <param>
- <key>tr_level</key>
- <value>0.0</value>
- </param>
- <param>
- <key>tr_mode</key>
- <value>qtgui.TRIG_MODE_FREE</value>
- </param>
- <param>
- <key>tr_tag</key>
- <value>""</value>
- </param>
- <param>
- <key>type</key>
- <value>complex</value>
- </param>
- <param>
- <key>update_time</key>
- <value>0.10</value>
- </param>
- <param>
- <key>wintype</key>
- <value>firdes.WIN_BLACKMAN_hARRIS</value>
- </param>
- <param>
- <key>ymax</key>
- <value>10</value>
+ <key>ref_scale</key>
+ <value>2</value>
</param>
<param>
- <key>ymin</key>
- <value>-140</value>
+ <key>sample_rate</key>
+ <value>samp_rate</value>
</param>
</block>
<block>
- <key>qtgui_time_sink_x</key>
+ <key>qtgui_freq_sink_x</key>
<param>
<key>autoscale</key>
<value>False</value>
</param>
<param>
+ <key>average</key>
+ <value>1.0</value>
+ </param>
+ <param>
+ <key>bw</key>
+ <value>samp_rate/decimate</value>
+ </param>
+ <param>
<key>alias</key>
<value></value>
</param>
<param>
+ <key>fc</key>
+ <value>0</value>
+ </param>
+ <param>
<key>comment</key>
<value></value>
</param>
@@ -2240,16 +1742,16 @@
<value></value>
</param>
<param>
- <key>entags</key>
+ <key>_enabled</key>
<value>True</value>
</param>
<param>
- <key>_enabled</key>
- <value>True</value>
+ <key>fftsize</key>
+ <value>8192</value>
</param>
<param>
<key>_coordinate</key>
- <value>(1072, 310)</value>
+ <value>(1008, 478)</value>
</param>
<param>
<key>gui_hint</key>
@@ -2265,7 +1767,7 @@
</param>
<param>
<key>id</key>
- <value>qtgui_time_sink_x_0</value>
+ <value>qtgui_freq_sink_x_0_0</value>
</param>
<param>
<key>legend</key>
@@ -2284,14 +1786,6 @@
<value></value>
</param>
<param>
- <key>marker1</key>
- <value>-1</value>
- </param>
- <param>
- <key>style1</key>
- <value>1</value>
- </param>
- <param>
<key>width1</key>
<value>1</value>
</param>
@@ -2301,21 +1795,13 @@
</param>
<param>
<key>color10</key>
- <value>"blue"</value>
+ <value>"dark blue"</value>
</param>
<param>
<key>label10</key>
<value></value>
</param>
<param>
- <key>marker10</key>
- <value>-1</value>
- </param>
- <param>
- <key>style10</key>
- <value>1</value>
- </param>
- <param>
<key>width10</key>
<value>1</value>
</param>
@@ -2332,14 +1818,6 @@
<value></value>
</param>
<param>
- <key>marker2</key>
- <value>-1</value>
- </param>
- <param>
- <key>style2</key>
- <value>1</value>
- </param>
- <param>
<key>width2</key>
<value>1</value>
</param>
@@ -2356,14 +1834,6 @@
<value></value>
</param>
<param>
- <key>marker3</key>
- <value>-1</value>
- </param>
- <param>
- <key>style3</key>
- <value>1</value>
- </param>
- <param>
<key>width3</key>
<value>1</value>
</param>
@@ -2380,14 +1850,6 @@
<value></value>
</param>
<param>
- <key>marker4</key>
- <value>-1</value>
- </param>
- <param>
- <key>style4</key>
- <value>1</value>
- </param>
- <param>
<key>width4</key>
<value>1</value>
</param>
@@ -2404,14 +1866,6 @@
<value></value>
</param>
<param>
- <key>marker5</key>
- <value>-1</value>
- </param>
- <param>
- <key>style5</key>
- <value>1</value>
- </param>
- <param>
<key>width5</key>
<value>1</value>
</param>
@@ -2428,14 +1882,6 @@
<value></value>
</param>
<param>
- <key>marker6</key>
- <value>-1</value>
- </param>
- <param>
- <key>style6</key>
- <value>1</value>
- </param>
- <param>
<key>width6</key>
<value>1</value>
</param>
@@ -2452,14 +1898,6 @@
<value></value>
</param>
<param>
- <key>marker7</key>
- <value>-1</value>
- </param>
- <param>
- <key>style7</key>
- <value>1</value>
- </param>
- <param>
<key>width7</key>
<value>1</value>
</param>
@@ -2476,14 +1914,6 @@
<value></value>
</param>
<param>
- <key>marker8</key>
- <value>-1</value>
- </param>
- <param>
- <key>style8</key>
- <value>1</value>
- </param>
- <param>
<key>width8</key>
<value>1</value>
</param>
@@ -2500,16 +1930,16 @@
<value></value>
</param>
<param>
- <key>marker9</key>
- <value>-1</value>
+ <key>width9</key>
+ <value>1</value>
</param>
<param>
- <key>style9</key>
- <value>1</value>
+ <key>maxoutbuf</key>
+ <value>0</value>
</param>
<param>
- <key>width9</key>
- <value>1</value>
+ <key>minoutbuf</key>
+ <value>0</value>
</param>
<param>
<key>name</key>
@@ -2520,22 +1950,18 @@
<value>1</value>
</param>
<param>
- <key>size</key>
- <value>1024</value>
+ <key>showports</key>
+ <value>True</value>
</param>
<param>
- <key>srate</key>
- <value>samp_rate</value>
+ <key>freqhalf</key>
+ <value>True</value>
</param>
<param>
<key>tr_chan</key>
<value>0</value>
</param>
<param>
- <key>tr_delay</key>
- <value>0</value>
- </param>
- <param>
<key>tr_level</key>
<value>0.0</value>
</param>
@@ -2544,10 +1970,6 @@
<value>qtgui.TRIG_MODE_FREE</value>
</param>
<param>
- <key>tr_slope</key>
- <value>qtgui.TRIG_SLOPE_POS</value>
- </param>
- <param>
<key>tr_tag</key>
<value>""</value>
</param>
@@ -2560,20 +1982,16 @@
<value>0.10</value>
</param>
<param>
- <key>ylabel</key>
- <value>Amplitude</value>
- </param>
- <param>
- <key>yunit</key>
- <value>""</value>
+ <key>wintype</key>
+ <value>firdes.WIN_BLACKMAN_hARRIS</value>
</param>
<param>
<key>ymax</key>
- <value>1</value>
+ <value>10</value>
</param>
<param>
<key>ymin</key>
- <value>-1</value>
+ <value>-140</value>
</param>
</block>
<block>
@@ -2604,7 +2022,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(752, 767)</value>
+ <value>(776, 471)</value>
</param>
<param>
<key>_rotation</key>
@@ -2659,7 +2077,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(392, 897)</value>
+ <value>(504, 785)</value>
</param>
<param>
<key>_rotation</key>
@@ -3350,7 +2768,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(792, 319)</value>
+ <value>(808, 111)</value>
</param>
<param>
<key>_rotation</key>
@@ -4425,7 +3843,7 @@
</param>
<param>
<key>_coordinate</key>
- <value>(504, 694)</value>
+ <value>(512, 462)</value>
</param>
<param>
<key>_rotation</key>
@@ -4578,12 +3996,6 @@
</block>
<connection>
<source_block_id>analog_const_source_x_0</source_block_id>
- <sink_block_id>blocks_float_to_complex_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>1</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_add_xx_0</source_block_id>
<sink_block_id>blocks_add_xx_1</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
@@ -4602,12 +4014,6 @@
</connection>
<connection>
<source_block_id>blocks_add_xx_1</source_block_id>
- <sink_block_id>qtgui_time_sink_x_0</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>
@@ -4619,12 +4025,6 @@
<sink_key>0</sink_key>
</connection>
<connection>
- <source_block_id>blocks_complex_to_mag_0</source_block_id>
- <sink_block_id>blocks_float_to_complex_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
<source_block_id>blocks_complex_to_mag_squared_0</source_block_id>
<sink_block_id>blocks_moving_average_xx_0_0</sink_block_id>
<source_key>0</source_key>
@@ -4638,35 +4038,11 @@
</connection>
<connection>
<source_block_id>blocks_file_source_0</source_block_id>
- <sink_block_id>blocks_complex_to_mag_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>blocks_multiply_const_vxx_1</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>blocks_multiply_xx_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_float_to_complex_0</source_block_id>
- <sink_block_id>blocks_multiply_xx_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>1</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_float_to_complex_0</source_block_id>
- <sink_block_id>blocks_multiply_xx_0_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
<source_block_id>blocks_message_burst_source_0</source_block_id>
<sink_block_id>blocks_null_sink_0_2</sink_block_id>
<source_key>0</source_key>
@@ -4697,42 +4073,12 @@
<sink_key>0</sink_key>
</connection>
<connection>
- <source_block_id>blocks_multiply_const_vxx_0</source_block_id>
- <sink_block_id>blocks_add_xx_0</sink_block_id>
- <source_key>0</source_key>
- <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>blocks_multiply_const_vxx_2</source_block_id>
- <sink_block_id>blocks_add_xx_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>1</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_multiply_xx_0</source_block_id>
- <sink_block_id>blocks_multiply_const_vxx_2</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_multiply_xx_0</source_block_id>
- <sink_block_id>blocks_multiply_xx_0_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>1</sink_key>
- </connection>
- <connection>
- <source_block_id>blocks_multiply_xx_0_0</source_block_id>
- <sink_block_id>blocks_multiply_const_vxx_0</sink_block_id>
- <source_key>0</source_key>
- <sink_key>0</sink_key>
- </connection>
- <connection>
<source_block_id>fir_filter_xxx_0</source_block_id>
<sink_block_id>blocks_null_sink_0_0</sink_block_id>
<source_key>0</source_key>
@@ -4751,6 +4097,12 @@
<sink_key>0</sink_key>
</connection>
<connection>
+ <source_block_id>logpwrfft_x_0</source_block_id>
+ <sink_block_id>blocks_file_sink_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>0</sink_key>
+ </connection>
+ <connection>
<source_block_id>rational_resampler_xxx_0_0</source_block_id>
<sink_block_id>qtgui_freq_sink_x_0_0</sink_block_id>
<source_key>0</source_key>
@@ -4776,6 +4128,12 @@
</connection>
<connection>
<source_block_id>uhd_usrp_source_0</source_block_id>
+ <sink_block_id>logpwrfft_x_0</sink_block_id>
+ <source_key>0</source_key>
+ <sink_key>0</sink_key>
+ </connection>
+ <connection>
+ <source_block_id>uhd_usrp_source_0</source_block_id>
<sink_block_id>rational_resampler_xxx_0_0</sink_block_id>
<source_key>0</source_key>
<sink_key>0</sink_key>
diff --git a/run.ipynb b/run.ipynb
new file mode 100644
index 0000000..5c61960
--- /dev/null
+++ b/run.ipynb
@@ -0,0 +1,254 @@
+{
+ "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",
+ "\n",
+ "import tcp_async\n",
+ "import 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",
+ "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": [
+ "samp_rate = 4000000 #samples / second\n",
+ "frequency_0 = samp_rate/10. #cycles / second\n",
+ "frequency_1 = samp_rate/9. #cycles / second\n",
+ "fft_size = 8192"
+ ]
+ },
+ {
+ "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": [
+ "import peakutils\n",
+ "def score(msg, frequency_0, frequency_1, samp_rate):\n",
+ " frequency_0_idx = np.round(frequency_0 / samp_rate * fft_size).astype(int)\n",
+ " frequency_1_idx = np.round(frequency_1 / samp_rate * fft_size).astype(int)\n",
+ " frequency_idx_diff = frequency_1_idx - frequency_0_idx\n",
+ " \n",
+ " start = frequency_0_idx % frequency_idx_diff + frequency_idx_diff / 2.\n",
+ " start = np.round(start).astype(int)\n",
+ " end = msg.shape[0] - frequency_idx_diff - (msg.shape[0] - start) % frequency_idx_diff\n",
+ " \n",
+ " msg_cut = msg[start:end]\n",
+ " \n",
+ " msg_cut = msg_cut.reshape(-1, frequency_idx_diff)\n",
+ " \n",
+ " msg_peaks = np.max(msg_cut, axis=1)\n",
+ " #plt.plot(msg_peaks, \"ro\")\n",
+ " \n",
+ " inter_mod = \\\n",
+ " (0.5 * (msg_peaks[8]/msg_peaks[7] + msg_peaks[9]/msg_peaks[10]),\n",
+ " 0.5 * (msg_peaks[8]/msg_peaks[6] + msg_peaks[9]/msg_peaks[11]),\n",
+ " 0.5 * (msg_peaks[8]/msg_peaks[5] + msg_peaks[9]/msg_peaks[12]),\n",
+ " 0.5 * (msg_peaks[8]/msg_peaks[4] + msg_peaks[9]/msg_peaks[13]),\n",
+ " 0.5 * (msg_peaks[8]/msg_peaks[3] + msg_peaks[9]/msg_peaks[14]),\n",
+ " 0.5 * (msg_peaks[8]/msg_peaks[2] + msg_peaks[9]/msg_peaks[15]),\n",
+ " 0.5 * (msg_peaks[8]/msg_peaks[1] + msg_peaks[9]/msg_peaks[16]))\n",
+ " \n",
+ " return(inter_mod)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "top.set_txgain(85)\n",
+ "for x2 in np.linspace(-0.15, 0.15, num = 15):\n",
+ " t2 = time.time()\n",
+ " for x3 in np.linspace(-0.15, 0.15, num = 14):\n",
+ " for x4 in np.linspace(-0.15, 0.15, num = 7):\n",
+ " path = gen_source.gen_file(frequency_0=frequency_0,\n",
+ " frequency_1=frequency_1,\n",
+ " samp_rate=samp_rate,\n",
+ " x2 = x2,\n",
+ " x3 = x3,\n",
+ " x4 = x4,\n",
+ " path='./np_twotone')\n",
+ " #a_load = np.fromfile(path, dtype=np.complex64)\n",
+ " #plt.plot(a_load.real[0:100])\n",
+ " \n",
+ " sync.has_msg()\n",
+ " np.array(sync.get_msgs(2))\n",
+ " msgs = np.array(sync.get_msgs(5))\n",
+ " inter_mod_avg = (np.max(score(msgs[0], frequency_0, frequency_1, samp_rate)) \n",
+ " + np.max(score(msgs[1], frequency_0, frequency_1, samp_rate)) \n",
+ " + np.max(score(msgs[2], frequency_0, frequency_1, samp_rate)) \n",
+ " + np.max(score(msgs[3], frequency_0, frequency_1, samp_rate)) \n",
+ " + np.max(score(msgs[4], frequency_0, frequency_1, samp_rate)))/5\n",
+ " msg = msgs[0]\n",
+ " \n",
+ " \n",
+ " print(\"inter_mod %.3f, x_2 %.3f, x_3 %.3f\" % (inter_mod_avg, x2, x3))\n",
+ " \n",
+ " plt.plot(msg)\n",
+ " plt.savefig(\"/tmp/out/inter_mod_%.3f_x_2_%.3f_x_3_%.3f_x_4_%.3f.png\" % (inter_mod_avg, x2, x3, x4))\n",
+ " plt.clf()\n",
+ " print(time.time() - t2)"
+ ]
+ },
+ {
+ "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": [
+ "path = gen_source.gen_file(frequency_0=frequency_0,\n",
+ " frequency_1=frequency_1,\n",
+ " x1 = 0,\n",
+ " x2 = 0,\n",
+ " x3 = 0,\n",
+ " x4 = 0,\n",
+ " samp_rate=samp_rate,\n",
+ " path='./np_twotone')\n",
+ "a_load = np.fromfile(path, dtype=np.complex64)\n",
+ "plt.plot(a_load.real[0:100])"
+ ]
+ },
+ {
+ "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": []
+ },
+ {
+ "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
+}
diff --git a/src/__init__.py b/src/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/__init__.py
diff --git a/src/gen_source.py b/src/gen_source.py
new file mode 100644
index 0000000..a8c2ef2
--- /dev/null
+++ b/src/gen_source.py
@@ -0,0 +1,32 @@
+import numpy as np
+
+
+def complex_exp(freq, samp_rate, periods, phase_deg=0):
+ t_max = 1.0 * samp_rate / freq * periods
+ t = np.arange(t_max)
+ fac = t / samp_rate * freq
+ phase = 1j * phase_deg/360*2*np.pi
+ ret = np.exp(phase + 1j * 2 * np.pi * fac - 1j * np.pi / 2, dtype=np.complex64)
+ return ret
+ret = complex_exp(10,40,2)
+
+
+def gen_file(frequency_0, frequency_1, x1 = 0, x2 = 0, x3 = 0, x4 = 0, samp_rate = 4000000, path = "./np_twotone"):
+ tone_0 = complex_exp(frequency_0, samp_rate, samp_rate/frequency_1)
+ tone_1 = complex_exp(frequency_1, samp_rate, samp_rate/frequency_0)
+
+ two_tone = (tone_0 + tone_1)
+ two_tone = two_tone \
+ + np.abs(two_tone)**1 * x1 \
+ + np.abs(two_tone)**2 * x2 \
+ + np.abs(two_tone)**3 * x3 \
+ + np.abs(two_tone)**4 * x4
+
+ two_tone = two_tone / np.max(two_tone) * 0.9
+
+ two_tone.tofile(path)
+
+ a_load = np.fromfile(path, dtype=np.complex64)
+ assert(np.isclose(a_load, two_tone).all()), "Inconsistent stored file"
+
+ return path
diff --git a/tcp_async.py b/tcp_async.py
index 5cd4a20..05cadd7 100644
--- a/tcp_async.py
+++ b/tcp_async.py
@@ -28,7 +28,7 @@ class _TcpAsyncClient(threading.Thread):
#Establish connection
sock = None
print("Connecting to asynchronous uhd message tcp port " + str(self.port))
- while 1:
+ while self.q_quit.empty():
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.ip_address, self.port))
diff --git a/tcp_sync.py b/tcp_sync.py
index faffe51..6a2e619 100644
--- a/tcp_sync.py
+++ b/tcp_sync.py
@@ -14,10 +14,12 @@ class _TcpSyncClient(threading.Thread):
ip_address = None
port = None
- def __init__(self, ip_address, port):
+ def __init__(self, ip_address, port, packet_size, packet_type):
super(_TcpSyncClient, self).__init__()
self.ip_address = ip_address
self.port = port
+ self.packet_size = packet_size
+ self.packet_type = packet_type
def __exit__(self):
self.stop()
@@ -28,7 +30,7 @@ class _TcpSyncClient(threading.Thread):
#Establish connection
sock = None
print("Connecting to synchronous uhd message tcp port " + str(self.port))
- while 1:
+ while self.q_quit.empty():
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.ip_address, self.port))
@@ -44,13 +46,24 @@ class _TcpSyncClient(threading.Thread):
sock.settimeout(None)
while self.q_quit.empty():
try:
- s = sock.recv(12)
+ s = ""
+
+ #concatenate to one package
+ while self.q_quit.empty():
+ s += sock.recv(self.packet_size)
+ if (len(s)) == self.packet_size:
+ break
+ if (len(s)) > self.packet_size:
+ print("received wrong size of length " + str(len(s)))
+ time.sleep(0.01)
+ return -1
+
res_tuple = struct.unpack(
- "fff",
+ self.packet_type,
s)
- assert(type(res_tuple) is tuple), (type(res_list), res_tuple)
self.queue.put(res_tuple)
except socket.timeout:
+ self.stop()
traceback.print_exc()
pass
@@ -65,8 +78,8 @@ class _TcpSyncClient(threading.Thread):
class UhdSyncMsg(object):
"""Creates a thread to connect to the synchronous uhd messages tcp port"""
- def __init__(self, ip_address = "127.0.0.1", port = 47009):
- self.tcpa = _TcpSyncClient(ip_address, port)
+ def __init__(self, ip_address = "127.0.0.1", port = 47009, packet_size = 3, packet_type = "fff"):
+ self.tcpa = _TcpSyncClient(ip_address, port, packet_size, packet_type)
self.tcpa.start()
def __exit__(self):
@@ -76,6 +89,13 @@ class UhdSyncMsg(object):
"""stop tcp thread"""
self.tcpa.stop()
+ def get_msgs(self, num):
+ """get received messages as string of integer"""
+ out = []
+ while len(out) < num:
+ out.append(self.tcpa.queue.get())
+ return out
+
def get_res(self):
"""get received messages as string of integer"""
out = []