diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-03-18 12:59:22 +0100 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-03-18 12:59:22 +0100 |
commit | 13bd8d0f2dc6195b73e1c15a82fbc172b4cda310 (patch) | |
tree | 30562d3265894b8e745b61c0d49b0abee27f69cf /lab-windows | |
parent | 4c7c927f3c1d24aa7ced382a5a417e5314e104c2 (diff) | |
download | master-thesis-13bd8d0f2dc6195b73e1c15a82fbc172b4cda310.tar.gz master-thesis-13bd8d0f2dc6195b73e1c15a82fbc172b4cda310.tar.bz2 master-thesis-13bd8d0f2dc6195b73e1c15a82fbc172b4cda310.zip |
Improve detector
Diffstat (limited to 'lab-windows')
-rw-r--r-- | lab-windows/scratch.ipynb | 348 |
1 files changed, 304 insertions, 44 deletions
diff --git a/lab-windows/scratch.ipynb b/lab-windows/scratch.ipynb index da795fd..d31ef92 100644 --- a/lab-windows/scratch.ipynb +++ b/lab-windows/scratch.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 3, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -10,6 +10,7 @@ "import csv\n", "import re\n", "import math\n", + "import struct\n", "\n", "import numpy as np\n", "from matplotlib import pyplot as plt\n", @@ -20,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -29,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -46,21 +47,13 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 12, "metadata": {}, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "<ipython-input-64-bdef8329a3e8>:1: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n", - " fig, axs = plt.subplots(2, 2, figsize=(15, 9))\n" - ] - }, - { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "c040d7b8285a4444abc23ec0ef8c0d45", + "model_id": "57f40afcd2214d0392a5fc7577843454", "version_major": 2, "version_minor": 0 }, @@ -97,7 +90,146 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "8b2507e2a7a24129acddcdbb4356f8df", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "fig, axs = plt.subplots(2, 2, figsize=(15, 9))\n", + "ax1, ax2, ax3, ax4 = axs.flatten()\n", + "\n", + "freqs_mod, freqs_clean = read_freq_log('data/meas_sig_audio_test.log'), read_freq_log('/mnt/c/Users/jaseg/shared/dsss_test_50hz_clean_improved.log')\n", + "\n", + "ax1.plot(freqs_mod)\n", + "ax1.grid()\n", + "\n", + "ax2.plot(freqs_clean)\n", + "ax2.grid()\n", + "\n", + "w = 512\n", + "\n", + "ax3.psd(freqs_mod[:80000], w, 100/128 * 10)\n", + "ax4.psd(freqs_clean[:80000], w, 100/128 * 10)\n", + "None" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "with open('data/dsss_test_demod_fixed_03.bin', 'wb') as f:\n", + " for freq in read_freq_log('data/dsss_test_demod_fixed_03.log'):\n", + " f.write(struct.pack('f', freq))" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d3a944613a184c44be006ef957770e31", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "[<matplotlib.lines.Line2D at 0x7f49ad047130>]" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fig, ax = plt.subplots()\n", + "ax.plot(read_freq_log('data/dsss_test_demod_fixed_03.log'))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "5d366527c29840da9404ec7b1e1e0665", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "(84250, 86000)" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fig, axs = plt.subplots(2, 1, figsize=(15, 6))\n", + "ax1, ax2 = axs.flatten()\n", + "\n", + "freqs_mod = read_freq_log('data/meas_sig_audio_test.log')\n", + "\n", + "with open('data/meas_sig_audio_test.bin', 'wb') as f:\n", + " for freq in freqs_mod:\n", + " f.write(struct.pack('f', freq))\n", + " \n", + "with open('data/ref_sig_audio_test.bin', 'rb') as f:\n", + " freqs_ref = np.array(list(struct.iter_unpack('f', f.read())))\n", + "\n", + "ax1.plot(freqs_mod)\n", + "ax1.set_title('measured')\n", + "ax1.grid()\n", + "ax2.plot(freqs_ref)\n", + "ax2.set_title('reference')\n", + "ax2.grid()\n", + "\n", + "ax1.set_xlim([84250+47, 86000+47])\n", + "ax2.set_xlim([84250, 86000])" + ] + }, + { + "cell_type": "code", + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -109,13 +241,13 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "f5f37f4970ae4d0fb5677c55045c6ebf", + "model_id": "bc4efa3809dd423482f1ef34974192c0", "version_major": 2, "version_minor": 0 }, @@ -125,41 +257,73 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "<ipython-input-19-55f36f700399>:6: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.\n", + " fig.tight_layout()\n" + ] } ], "source": [ - "fig, axs = plt.subplots(2, 2, figsize=(15, 9))\n", + "# We see artifacts of the 128sp processing window in the analog readings if we process a buffer immediately after capture. We can reduce these artifacts by deferring the sampling a few milliseconds into the capture period.\n", + "# The reason for this is presumably a suboptimal power layout on the cheap f407 devboard leading to CPU load changes dumping noise into our ADC supply.\n", + "# In time domain plots we can see frequent high spikes in ADC counts that would be in accordance with this conjecture.\n", + "\n", + "fig, axs = plt.subplots(2, 2, figsize=(15, 9), sharey='row', gridspec_kw={'hspace': 0.2, 'wspace': 0.05})\n", + "fig.tight_layout()\n", "ax1, ax2, ax3, ax4 = axs.flatten()\n", "\n", - "raw_50hz, raw_silence = read_raw_log('/mnt/c/Users/jaseg/shared/rawlog_50hz_clean.log'), read_raw_log('/mnt/c/Users/jaseg/shared/rawlog_silence_clean3.log')\n", + "raw_left, raw_right = read_raw_log('data/rawlog_silence_clean.log'), read_raw_log('data/rawlog_silence_clean3.log')\n", + "raw_left = raw_left[26000:-10000].astype(float)\n", "\n", - "ax1.plot(raw_50hz)\n", + "raw_right = raw_right[26000:]\n", + "raw_right = raw_right[:len(raw_left)].astype(float)\n", + "\n", + "raw_left -= np.mean(raw_left)\n", + "raw_right -= np.mean(raw_right)\n", + "\n", + "ax1.set_title('Immediate processing')\n", + "ax1.plot(raw_left)\n", "ax1.grid()\n", - "#for x in range(0, len(raw_50hz), 128):\n", - "# ax1.axvline(x, color='red', alpha=0.3)\n", + "for x in range(0, len(raw_left), 128):\n", + " ax1.axvline(x, color='red', alpha=0.3)\n", "\n", - "ax2.plot(raw_silence)\n", + "ax2.set_title('Deferred processing')\n", + "ax2.plot(raw_right)\n", "ax2.grid()\n", - "#for x in range(0, len(raw_silence), 128):\n", - "# ax2.axvline(x, color='red', alpha=0.3)\n", + "for x in range(0, len(raw_right), 128):\n", + " ax2.axvline(x, color='red', alpha=0.3)\n", "\n", - "w = 16384\n", + "ax1.set_xlim([0, 1000])\n", + "ax1.set_ylim([-200, 200])\n", + "ax2.set_xlim([0, 1000])\n", + "ax2.set_ylim([-200, 200])\n", + "ax1.set_xlabel('t [ms]')\n", + "ax2.set_xlabel('t [ms]')\n", + "ax1.set_ylabel('ADC reading [counts]')\n", "\n", - "ax3.psd(raw_50hz, w, 1e3)\n", + "w = 2048\n", "\n", - "ax4.psd(raw_silence, w, 1e3)\n", + "ax3.psd(raw_left, w, 1e3)\n", + "ax4.psd(raw_right, w, 1e3)\n", + "ax3.set_ylim([-10, 26])\n", + "ax4.set_ylim([-10, 26])\n", + "ax4.set_ylabel(None)\n", "None" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "eba72dea09bc45ff9de68cb22b352fb3", + "model_id": "291774359d674902aad182268ec9c469", "version_major": 2, "version_minor": 0 }, @@ -174,8 +338,8 @@ "source": [ "fig, ax = plt.subplots(figsize=(12, 6))\n", "\n", - "raw_silence = read_raw_log('/mnt/c/Users/jaseg/shared/rawlog_silence_clean.log')\n", - "raw_silence2 = read_raw_log('/mnt/c/Users/jaseg/shared/rawlog_silence_clean3.log')\n", + "raw_silence = read_raw_log('data/rawlog_silence_clean.log')\n", + "raw_silence2 = read_raw_log('data/rawlog_silence_clean3.log')\n", "\n", "raw_silence = raw_silence.reshape([-1, 128])\n", "le_mean = raw_silence.mean(axis=0)\n", @@ -189,21 +353,21 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "<ipython-input-90-5a220009d359>:1: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n", - " fig, axs = plt.subplots(2, 2, figsize=(15, 9))\n" + "<ipython-input-40-132a47f1202f>:1: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).\n", + " fig, axs = plt.subplots(4, 1, figsize=(15, 9), sharex=True)\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d9143b226974466aaec05a70592ac69e", + "model_id": "2740bc857e6c4296b9ca74ada34fbb1d", "version_major": 2, "version_minor": 0 }, @@ -216,23 +380,119 @@ } ], "source": [ - "fig, axs = plt.subplots(2, 2, figsize=(15, 9))\n", + "fig, axs = plt.subplots(4, 1, figsize=(15, 9), sharex=True)\n", "ax1, ax2, ax3, ax4 = axs.flatten()\n", "\n", - "raw_d, raw_e = read_raw_log('/mnt/c/Users/jaseg/shared/rawlog_test_d.log'), read_raw_log('/mnt/c/Users/jaseg/shared/rawlog_test_e.log')\n", + "#with open('data/meas_sig_audio_test_processed.log') as f:\n", + "with open('data/meas_sig_audio_test_fixed_03.log') as f:\n", + " lines = f.readlines()\n", + " data = np.array([ [float(x) for x in line.split(': ')[1].split()] for line in lines if not line.startswith('GROUP:') ])\n", + " groups = [ int(line.split(' ')[2]) for line in lines if line.startswith('GROUP:') ]\n", "\n", - "ax1.plot(raw_d)\n", + "ax1.plot(data[:,0])\n", "ax1.grid()\n", + "ax1.set_xlim([4000, 16000])\n", + "ax1.set_ylim([-0.02, 0.1])\n", "\n", - "ax2.plot(raw_e)\n", + "ax2.plot(data[:,1:-2:2])\n", "ax2.grid()\n", + "ax2.set_ylim([-0.6, 0.6])\n", "\n", - "w = 16384\n", + "ax3.plot(data[:,2:-2:2])\n", + "ax3.grid()\n", "\n", - "ax3.psd(raw_d, w, 1e3)\n", - "ax4.psd(raw_e, w, 1e3)\n", - "#ax3.psd(raw_silence, w, 1e3)\n", - "None" + "ax4.plot(data[:,-2:])\n", + "ax4.grid()\n", + "\n", + "for x in groups:\n", + " ax4.axvline(x, color='red', alpha=0.4)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "<matplotlib.lines.Line2D at 0x7f497186d6d0>" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ax4.axvline(12433)\n", + "ax4.axvline(12164)\n", + "ax4.axvline(12475)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "cff56db4807048cda06ae8b15b0c6344", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "fig, axs = plt.subplots(4, 1, figsize=(15, 9), sharex=True)\n", + "ax1, ax2, ax3, ax4 = axs.flatten()\n", + "\n", + "with open('data/ref_sig_audio_test_processed.log') as f:\n", + " lines = f.readlines()\n", + " data = np.array([ [float(x) for x in line.split(': ')[1].split()] for line in lines if not line.startswith('GROUP:') ])\n", + " groups = [ int(line.split(': ')[1]) for line in lines if line.startswith('GROUP:') ]\n", + "\n", + "ax1.plot(data[:,0])\n", + "ax1.grid()\n", + "ax1.set_xlim([82000, 95000])\n", + "ax1.set_ylim([-0.02, 0.1])\n", + "\n", + "ax2.plot(data[:,1:-2:2])\n", + "ax2.grid()\n", + "ax2.set_ylim([-0.6, 0.6])\n", + "\n", + "ax3.plot(data[:,2:-2:2])\n", + "ax3.grid()\n", + "\n", + "ax4.plot(data[:,-2:])\n", + "ax4.grid()\n", + "\n", + "for x in groups:\n", + " ax4.axvline(x, color='red', alpha=0.4)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[516, 518, 4402, 4404, 5537, 7238, 12585, 17497, 17724, 34074, 34076, 41628, 44677, 46287, 49371, 49837, 53877, 54554, 56666, 56949, 60923, 67313, 67744, 67746, 68392, 79601, 84707, 84709, 84711, 85017, 85019, 85021, 85327, 85329, 85637, 85947, 85949, 85951, 86257, 86259, 86261, 86567, 86569, 86571, 86877, 86879, 86881, 87187, 87189, 87191, 87498, 87500, 87807, 87809, 87811, 88117, 88119, 88121, 88427, 88429, 88431, 88488, 88737, 88739, 88741, 89047, 89049, 89051, 89357, 89359, 89361, 89668, 89670, 89730, 89978, 89980, 90287, 90289, 90291, 90598, 90600, 90602, 90907, 90909, 90911, 91217, 91219, 91221, 91527, 91529, 91531, 91837, 91839, 91841, 92148, 92150, 92458, 92460, 92768, 92770, 93078, 93080, 93388, 93390, 93392, 93698, 93700, 93702, 94008, 94010, 94318, 94320]\n" + ] + } + ], + "source": [ + "print(groups)" ] }, { |