diff options
Diffstat (limited to 'controller/fw/src/dsss_demod.c')
-rw-r--r-- | controller/fw/src/dsss_demod.c | 28 |
1 files changed, 15 insertions, 13 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; |