diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-04-17 17:59:08 +0200 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-04-17 17:59:08 +0200 |
commit | 87ae7dfcb35d9a55950eecc2116d13d73b2b9ece (patch) | |
tree | 090946c28eb7b9d3028844bf4e0dcc01ddb29664 /controller/fw/src | |
parent | e505627adad7510673f983cd158016342aa1bdfc (diff) | |
download | master-thesis-87ae7dfcb35d9a55950eecc2116d13d73b2b9ece.tar.gz master-thesis-87ae7dfcb35d9a55950eecc2116d13d73b2b9ece.tar.bz2 master-thesis-87ae7dfcb35d9a55950eecc2116d13d73b2b9ece.zip |
fw simulator: WIP
Diffstat (limited to 'controller/fw/src')
-rw-r--r-- | controller/fw/src/dsss_demod.c | 28 | ||||
-rw-r--r-- | controller/fw/src/dsss_demod.h | 17 | ||||
-rw-r--r-- | controller/fw/src/simulation.h | 2 |
3 files changed, 25 insertions, 22 deletions
diff --git a/controller/fw/src/dsss_demod.c b/controller/fw/src/dsss_demod.c index f9efda6..58dae9a 100644 --- a/controller/fw/src/dsss_demod.c +++ b/controller/fw/src/dsss_demod.c @@ -13,23 +13,23 @@ #include "simulation.h" #include "generated/dsss_gold_code.h" -#include "generated/dsss_butter_filter.h" +// #include "generated/dsss_butter_filter.h" /* Generated CWT wavelet LUT */ extern const float * const dsss_cwt_wavelet_table; -struct iir_biquad cwt_filter_bq[DSSS_FILTER_CLEN] = {DSSS_FILTER_COEFF}; +//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); -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); +//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); 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); static void group_received(struct dsss_demod_state *st); -static uint8_t decode_peak(int peak_ch, float peak_ampl); +static symbol_t decode_peak(int peak_ch, float peak_ampl); #ifdef SIMULATION void debug_print_vector(const char *name, size_t len, const float *data, size_t stride, bool index, bool debug) { @@ -61,7 +61,7 @@ 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; + bool log_groups = false; st->signal[st->signal_wpos] = new_value; st->signal_wpos = (st->signal_wpos + 1) % ARRAY_LENGTH(st->signal); @@ -99,7 +99,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts) max_ts = ts; } - if (fabsf(val) > DSSS_THESHOLD_FACTOR) + if (fabsf(val) > DSSS_THRESHOLD_FACTOR) found = true; } if (log) DEBUG_PRINTN("%f %d ", max_val, found); @@ -134,12 +134,12 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts) /* Map a sequence match to a data symbol. This maps the sequence's index number to the 2nd to n+2nd bit of the result, * and maps the polarity of detection to the LSb. 5-bit example: * - * [0, S, S, S, S, S, S, P] ; S ^= symbol index (0 - 2^n+1), P ^= symbol polarity + * [0, S, S, S, S, S, S, P] ; S ^= symbol index (0 - 2^n+1 so we need just about n+1 bit), P ^= symbol polarity * * Symbol polarity is preserved from transmitter to receiver. The symbol index is n+1 bit instead of n bit since we have * 2^n+1 symbols to express, one too many for an n-bit index. */ -uint8_t decode_peak(int peak_ch, float peak_ampl) { +symbol_t decode_peak(int peak_ch, float peak_ampl) { return (peak_ch<<1) | (peak_ampl > 0); } @@ -157,7 +157,7 @@ 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 debug = false; bool header_printed = false; for (size_t i=0; i<DSSS_MATCHER_CACHE_SIZE; i++) { @@ -172,7 +172,7 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u 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); + if (debug) DEBUG_PRINTN(" skip %zd 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; @@ -195,7 +195,7 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u header_printed = true; DEBUG_PRINTN("windows %zu\n", ts); } - if (debug) DEBUG_PRINTN(" %d ", i); + if (debug) DEBUG_PRINTN(" %zd ", i); /* Process window results */ assert(i < DSSS_MATCHER_CACHE_SIZE); assert(0 <= states[i].data_pos && states[i].data_pos < TRANSMISSION_SYMBOLS); @@ -235,7 +235,7 @@ static float score_group(const struct group *g, int phase_delta) { } void group_received(struct dsss_demod_state *st) { - bool debug = true; + bool debug = false; 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); @@ -305,6 +305,7 @@ 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++) @@ -320,6 +321,7 @@ 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/dsss_demod.h b/controller/fw/src/dsss_demod.h index 448abb4..b865d83 100644 --- a/controller/fw/src/dsss_demod.h +++ b/controller/fw/src/dsss_demod.h @@ -10,8 +10,12 @@ /* FIXME: move to makefile */ #define DSSS_MATCHER_CACHE_SIZE 8 -/* FIXME: move to more appropriate header */ -#define PAYLOAD_DATA_BYTE ((PAYLOAD_DATA_BIT+7)/8) + +#if DSSS_GOLD_CODE_NBITS < 8 +typedef uint8_t symbol_t; +#else +typedef uint16_t symbol_t; +#endif struct iir_biquad { float a[2]; @@ -43,12 +47,9 @@ struct matcher_state { int last_skips; int candidate_skips; -#if DSSS_GOLD_CODE_NBITS > 7 -#error DSSS_GOLD_CODE_NBITS is too large for matcher_state.data data type (uint8_t) -#endif - uint8_t data[TRANSMISSION_SYMBOLS]; + symbol_t data[TRANSMISSION_SYMBOLS]; int data_pos; - uint8_t candidate_data; + symbol_t candidate_data; }; struct dsss_demod_state { @@ -66,7 +67,7 @@ struct dsss_demod_state { }; -extern void handle_dsss_received(uint8_t data[static TRANSMISSION_SYMBOLS]); +extern void handle_dsss_received(symbol_t data[static TRANSMISSION_SYMBOLS]); void dsss_demod_init(struct dsss_demod_state *st); void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts); diff --git a/controller/fw/src/simulation.h b/controller/fw/src/simulation.h index e813de7..2734e5b 100644 --- a/controller/fw/src/simulation.h +++ b/controller/fw/src/simulation.h @@ -3,7 +3,7 @@ #ifdef SIMULATION #include <stdio.h> -#define DEBUG_PRINTN(...) fprintf(stderr, __VA_ARGS__) +#define DEBUG_PRINTN(...) printf(__VA_ARGS__) #define DEBUG_PRINTNF(fmt, ...) DEBUG_PRINTN("%s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__) #define DEBUG_PRINT(fmt, ...) DEBUG_PRINTNF(fmt "\n", ##__VA_ARGS__) #else |