summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-18 12:59:22 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-18 12:59:22 +0100
commit13bd8d0f2dc6195b73e1c15a82fbc172b4cda310 (patch)
tree30562d3265894b8e745b61c0d49b0abee27f69cf
parent4c7c927f3c1d24aa7ced382a5a417e5314e104c2 (diff)
downloadmaster-thesis-13bd8d0f2dc6195b73e1c15a82fbc172b4cda310.tar.gz
master-thesis-13bd8d0f2dc6195b73e1c15a82fbc172b4cda310.tar.bz2
master-thesis-13bd8d0f2dc6195b73e1c15a82fbc172b4cda310.zip
Improve detector
-rw-r--r--controller/fw/Makefile2
-rw-r--r--controller/fw/src/dsss_demod.c49
-rw-r--r--controller/fw/src/main.c17
-rw-r--r--controller/fw/src/sr_global.h5
-rw-r--r--lab-windows/scratch.ipynb348
5 files changed, 351 insertions, 70 deletions
diff --git a/controller/fw/Makefile b/controller/fw/Makefile
index 50d162d..0faea30 100644
--- a/controller/fw/Makefile
+++ b/controller/fw/Makefile
@@ -25,7 +25,7 @@ FMEAS_SAMPLING_RATE ?= $(shell echo $(FMEAS_ADC_SAMPLING_RATE) / \($(FMEAS_FFT_
DSSS_GOLD_CODE_NBITS ?= 5
DSSS_DECIMATION ?= 10
# TODO maybe auto adjust this based on detection rate?
-DSSS_THESHOLD_FACTOR ?= 6.0f
+DSSS_THESHOLD_FACTOR ?= 5.0f
DSSS_WAVELET_WIDTH ?= 7.3
DSSS_WAVELET_LUT_SIZE ?= 69
DSSS_FILTER_FC ?= 3e-3
diff --git a/controller/fw/src/dsss_demod.c b/controller/fw/src/dsss_demod.c
index 0758525..f9efda6 100644
--- a/controller/fw/src/dsss_demod.c
+++ b/controller/fw/src/dsss_demod.c
@@ -23,10 +23,8 @@ struct iir_biquad cwt_filter_bq[DSSS_FILTER_CLEN] = {DSSS_FILTER_COEFF};
void debug_print_vector(const char *name, size_t len, const float *data, size_t stride, bool index, bool debug);
static float gold_correlate_step(const size_t ncode, const float a[DSSS_CORRELATION_LENGTH], size_t offx, bool debug);
static float cwt_convolve_step(const float v[DSSS_WAVELET_LUT_SIZE], size_t offx);
-#if 0
static float run_iir(const float x, const int order, const struct iir_biquad q[order], struct iir_biquad_state st[order]);
static float run_biquad(float x, const struct iir_biquad *const q, struct iir_biquad_state *const restrict st);
-#endif
static void matcher_init(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE]);
static void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE],
uint64_t ts, int peak_ch, float peak_ampl);
@@ -41,7 +39,7 @@ void debug_print_vector(const char *name, size_t len, const float *data, size_t
if (index) {
DEBUG_PRINTN(" %16s [", "");
for (size_t i=0; i<len; i++)
- DEBUG_PRINTN("%8zd ", i);
+ DEBUG_PRINTN("%8zu ", i);
DEBUG_PRINTN("]\n");
}
@@ -62,6 +60,8 @@ void dsss_demod_init(struct dsss_demod_state *st) {
void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts) {
//const float hole_patching_threshold = 0.01 * DSSS_CORRELATION_LENGTH;
+ bool log = false;
+ bool log_groups = true;
st->signal[st->signal_wpos] = new_value;
st->signal_wpos = (st->signal_wpos + 1) % ARRAY_LENGTH(st->signal);
@@ -80,6 +80,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts)
for (size_t i=0; i<DSSS_GOLD_CODE_COUNT; i++)
avg += fabsf(cwt[i]);
avg /= (float)DSSS_GOLD_CODE_COUNT;
+ if (log) DEBUG_PRINTN("%6zu: %f ", ts, avg);
/* FIXME fix this filter */
//avg = run_iir(avg, ARRAY_LENGTH(cwt_filter_bq), cwt_filter_bq, st->cwt_filter.st);
@@ -89,18 +90,21 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts)
bool found = false;
for (size_t i=0; i<DSSS_GOLD_CODE_COUNT; i++) {
float val = cwt[i] / avg;
+ if (log) DEBUG_PRINTN("%f ", cwt[i]);
+ if (log) DEBUG_PRINTN("%f ", val);
if (fabsf(val) > fabsf(max_val)) {
max_val = val;
max_ch = i;
max_ts = ts;
-
- if (fabsf(val) > DSSS_THESHOLD_FACTOR)
- found = true;
}
+
+ if (fabsf(val) > DSSS_THESHOLD_FACTOR)
+ found = true;
}
+ if (log) DEBUG_PRINTN("%f %d ", max_val, found);
+ if (log) DEBUG_PRINTN("\n");
- /* FIXME: skipped sample handling here */
matcher_tick(st->matcher_cache, ts, max_ch, max_val);
if (found) {
@@ -116,6 +120,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts)
/* We're between groups */
return;
+ if (log_groups) DEBUG_PRINTN("GROUP: %zu %d %f\n", st->group.max_ts, st->group.max_ch, st->group.max);
/* A group ended. Process result. */
group_received(st);
@@ -152,7 +157,9 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
const float score_depreciation = 0.1f; /* 0.0 -> no depreciation, 1.0 -> complete disregard */
const int current_phase = ts % DSSS_CORRELATION_LENGTH;
const int max_skips = TRANSMISSION_SYMBOLS/4*3;
+ bool debug = true;
+ bool header_printed = false;
for (size_t i=0; i<DSSS_MATCHER_CACHE_SIZE; i++) {
if (states[i].last_phase == -1)
continue; /* Inactive entry */
@@ -161,6 +168,11 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
/* Skip sampling */
float score = fabsf(peak_ampl) * (1.0f - skip_sampling_depreciation);
if (score > states[i].candidate_score) {
+ if (debug && !header_printed) {
+ header_printed = true;
+ DEBUG_PRINTN("windows %zu\n", ts);
+ }
+ if (debug) DEBUG_PRINTN(" skip %d old=%f new=%f\n", i, states[i].candidate_score, score);
/* We win, update candidate */
assert(i < DSSS_MATCHER_CACHE_SIZE);
states[i].candidate_score = score;
@@ -175,7 +187,15 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
* process a group a couple ticks after its peak. We have to make sure the window is still open at this point.
* This means we have to match against group_phase_tolerance should a little bit loosely.
*/
- if (abs(states[i].last_phase - current_phase) == group_phase_tolerance + DSSS_DECIMATION) {
+ int phase_delta = current_phase - states[i].last_phase;
+ if (phase_delta < 0)
+ phase_delta += DSSS_CORRELATION_LENGTH;
+ if (phase_delta == group_phase_tolerance + DSSS_DECIMATION) {
+ if (debug && !header_printed) {
+ header_printed = true;
+ DEBUG_PRINTN("windows %zu\n", ts);
+ }
+ if (debug) DEBUG_PRINTN(" %d ", i);
/* Process window results */
assert(i < DSSS_MATCHER_CACHE_SIZE);
assert(0 <= states[i].data_pos && states[i].data_pos < TRANSMISSION_SYMBOLS);
@@ -183,17 +203,21 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u
states[i].data_pos = states[i].data_pos + 1;
states[i].last_score = score_depreciation * states[i].last_score +
(1.0f - score_depreciation) * states[i].candidate_score;
+ if (debug) DEBUG_PRINTN("commit pos=%d val=%d score=%f ", states[i].data_pos, states[i].candidate_data, states[i].last_score);
states[i].candidate_score = 0.0f;
states[i].last_skips += states[i].candidate_skips;
if (states[i].last_skips > max_skips) {
+ if (debug) DEBUG_PRINTN("expire ");
states[i].last_phase = -1; /* invalidate entry */
} else if (states[i].data_pos == TRANSMISSION_SYMBOLS) {
+ if (debug) DEBUG_PRINTN("match ");
/* Frame received completely */
handle_dsss_received(states[i].data);
states[i].last_phase = -1; /* invalidate entry */
}
+ if (debug) DEBUG_PRINTN("\n");
}
}
}
@@ -211,6 +235,7 @@ static float score_group(const struct group *g, int phase_delta) {
}
void group_received(struct dsss_demod_state *st) {
+ bool debug = true;
const int group_phase = st->group.max_ts % DSSS_CORRELATION_LENGTH;
/* This is the score of a decoding starting at this group (with no context) */
float base_score = score_group(&st->group, 0);
@@ -234,6 +259,7 @@ void group_received(struct dsss_demod_state *st) {
float group_score = score_group(&st->group, phase_delta);
if (st->matcher_cache[i].candidate_score < group_score) {
assert(i < DSSS_MATCHER_CACHE_SIZE);
+ if (debug) DEBUG_PRINTN(" appending %zu %d score=%f pd=%d\n", i, decode_peak(st->group.max_ch, st->group.max), group_score, phase_delta);
/* Append to entry */
st->matcher_cache[i].candidate_score = group_score;
st->matcher_cache[i].candidate_phase = group_phase;
@@ -243,7 +269,8 @@ void group_received(struct dsss_demod_state *st) {
}
/* Search for weakest entry */
- float score = st->matcher_cache[i].last_score;
+ /* TODO figure out this fitness function */
+ float score = st->matcher_cache[i].last_score * (1.5f + 1.0f/st->matcher_cache[i].data_pos);
if (score < min_score) {
min_idx = i;
min_score = score;
@@ -252,6 +279,7 @@ void group_received(struct dsss_demod_state *st) {
/* If we found empty entries, replace one by a new decoding starting at this group */
if (empty_idx >= 0) {
+ if (debug) DEBUG_PRINTN(" empty %zd %d\n", empty_idx, decode_peak(st->group.max_ch, st->group.max));
assert(0 <= empty_idx && empty_idx < DSSS_MATCHER_CACHE_SIZE);
st->matcher_cache[empty_idx].last_phase = group_phase;
st->matcher_cache[empty_idx].candidate_score = base_score;
@@ -264,6 +292,7 @@ void group_received(struct dsss_demod_state *st) {
/* If the weakest decoding in cache is weaker than a new decoding starting here, replace it */
} else if (min_score < base_score && min_idx >= 0) {
+ if (debug) DEBUG_PRINTN(" min %zd %d\n", min_idx, decode_peak(st->group.max_ch, st->group.max));
assert(0 <= min_idx && min_idx < DSSS_MATCHER_CACHE_SIZE);
st->matcher_cache[min_idx].last_phase = group_phase;
st->matcher_cache[min_idx].candidate_score = base_score;
@@ -276,7 +305,6 @@ void group_received(struct dsss_demod_state *st) {
}
}
-#if 0
float run_iir(const float x, const int order, const struct iir_biquad q[order], struct iir_biquad_state st[order]) {
float intermediate = x;
for (int i=0; i<(order+1)/2; i++)
@@ -292,7 +320,6 @@ float run_biquad(float x, const struct iir_biquad *const q, struct iir_biquad_st
st->reg[0] = intermediate;
return out;
}
-#endif
float cwt_convolve_step(const float v[DSSS_WAVELET_LUT_SIZE], size_t offx) {
float sum = 0.0f;
diff --git a/controller/fw/src/main.c b/controller/fw/src/main.c
index 6589297..814c723 100644
--- a/controller/fw/src/main.c
+++ b/controller/fw/src/main.c
@@ -216,23 +216,14 @@ int main(void)
con_printf("Booted.\r\n");
while (23) {
if (adc_fft_buf_ready_idx != -1) {
+ for (int i=0; i<168*1000*2; i++)
+ asm volatile ("nop");
GPIOA->BSRR = 1<<11;
- //adc_fft_buf_ready_idx = !adc_fft_buf_ready_idx; /* DEBUG */
- //DEBUG:
- //memcpy(adc_fft_buf[!adc_fft_buf_ready_idx], adc_fft_buf[adc_fft_buf_ready_idx] + FMEAS_FFT_LEN/2, sizeof(adc_fft_buf[0][0]) * FMEAS_FFT_LEN/2);
+ memcpy(adc_fft_buf[!adc_fft_buf_ready_idx], adc_fft_buf[adc_fft_buf_ready_idx] + FMEAS_FFT_LEN/2, sizeof(adc_fft_buf[0][0]) * FMEAS_FFT_LEN/2);
+ GPIOA->BSRR = 1<<11<<16;
for (int i=0; i<168*1000*2; i++)
asm volatile ("nop");
- /* BEGIN DEBUG */
- con_printf_blocking("\r\n%06d: ", freq_sample_ts);
- int old_idx = adc_fft_buf_ready_idx;
- for (int i=0; i<FMEAS_FFT_LEN/2; i++)
- con_printf_blocking("%03x ", adc_fft_buf[old_idx][FMEAS_FFT_LEN/2 + i]);
- adc_fft_buf_ready_idx = -1;
- freq_sample_ts++; /* TODO: also increase in case of freq measurement error? */
- GPIOA->BSRR = 1<<11<<16;
- continue;
- /* END DEBUG */
GPIOA->BSRR = 1<<11;
float out;
diff --git a/controller/fw/src/sr_global.h b/controller/fw/src/sr_global.h
index 451cce0..97db4e4 100644
--- a/controller/fw/src/sr_global.h
+++ b/controller/fw/src/sr_global.h
@@ -2,9 +2,12 @@
#define __SR_GLOBAL_H__
#include <stdint.h>
+#include <sys/types.h>
+
+#ifndef SIMULATION
#include <stm32f407xx.h>
#include <stm32f4_isr.h>
-#include <sys/types.h>
+#endif
#define UNUSED(x) ((void) x)
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
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)"
]
},
{