From 55ebbcbdbc6d9513012a60a143c92eddb90f631d Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 6 Mar 2020 12:39:21 +0100 Subject: Finish DSSS demodulation stage 1 --- controller/fw/src/dsss_demod.c | 88 +++++++++++++++++++++--------------------- controller/fw/src/dsss_demod.h | 2 +- 2 files changed, 46 insertions(+), 44 deletions(-) (limited to 'controller/fw/src') diff --git a/controller/fw/src/dsss_demod.c b/controller/fw/src/dsss_demod.c index 7feb41b..cc1c34e 100644 --- a/controller/fw/src/dsss_demod.c +++ b/controller/fw/src/dsss_demod.c @@ -22,70 +22,77 @@ float gold_correlate_step(const size_t ncode, const float a[DSSS_CORRELATION_LEN float cwt_convolve_step(const float v[DSSS_WAVELET_LUT_SIZE], size_t offx); float run_iir(const float x, const int order, const struct iir_biquad q[order], struct iir_biquad_state st[order]); float run_biquad(float x, const struct iir_biquad *const q, struct iir_biquad_state *const restrict st); +void debug_print_vector(const char *name, size_t len, const float *data, size_t stride, bool index, bool debug); #ifdef SIMULATION -void dsss_demod_step(struct dsss_demod_state *st, float new_value, size_t sim_pos) { -#else /* SIMULATION */ +void debug_print_vector(const char *name, size_t len, const float *data, size_t stride, bool index, bool debug) { + if (!debug) + return; + + if (index) { + DEBUG_PRINTN(" %16s [", ""); + for (size_t i=0; i 1000) + && (sim_pos % DSSS_CORRELATION_LENGTH == DSSS_CORRELATION_LENGTH-1); + + if (debug) DEBUG_PRINT("Iteration %zd: signal=%f", sim_pos, new_value); +#else void dsss_demod_step(struct dsss_demod_state *st, float new_value) { -#endif /* SIMULATION */ +#endif -//#define DEBUG_PRINT(...) ((void)0) -//#define DEBUG_PRINTN(...) ((void)0) - bool debug = sim_pos % DSSS_CORRELATION_LENGTH == DSSS_CORRELATION_LENGTH-1; - //bool debug = sim_pos > 1000; - if (debug) DEBUG_PRINT("Iteration %zd", sim_pos); //const float peak_group_threshold = 0.05 * DSSS_CORRELATION_LENGTH; //const float hole_patching_threshold = 0.01 * DSSS_CORRELATION_LENGTH; st->signal[st->signal_wpos] = new_value; st->signal_wpos = (st->signal_wpos + 1) % ARRAY_LENGTH(st->signal); - if (debug) DEBUG_PRINT(" signal: %f", new_value); /* use new, incremented wpos for gold_correlate_step as first element of old data in ring buffer */ for (size_t i=0; icorrelation[i][st->correlation_wpos] = gold_correlate_step(i, st->signal, st->signal_wpos, false); - /* debug */ - if (debug) { - DEBUG_PRINTN(" ["); - for (size_t i=0; icorrelation[i][st->correlation_wpos]); - DEBUG_PRINTN("]\n"); - } - /* end */ + + debug_print_vector("correlation", + DSSS_GOLD_CODE_COUNT, &st->correlation[0][st->correlation_wpos], DSSS_WAVELET_LUT_SIZE, true, debug); + st->correlation_wpos = (st->correlation_wpos + 1) % ARRAY_LENGTH(st->correlation[0]); float cwt[DSSS_GOLD_CODE_COUNT]; for (size_t i=0; icorrelation[i], st->correlation_wpos); - /* debug */ - if (debug) DEBUG_PRINTN(" cwt: ["); - for (size_t i=0; icwt_filter[i].st); - /* debug */ - if (debug) DEBUG_PRINTN(" avg: ["); - for (size_t i=0; icorrelation[record_channel][st->correlation_wpos], cwt[record_channel], avg[record_channel]); float max_val = st->group.max; int max_ch = st->group.max_ch; int max_idx = st->group.max_idx + 1; bool found = false; - //if (debug) DEBUG_PRINTN(" rel: ["); for (size_t i=0; i DSSS_THESHOLD_FACTOR) found = true; @@ -96,12 +103,6 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) { max_idx = st->group.len; } } - //if (debug) DEBUG_PRINTN("]\n"); - - /* debug */ - if (debug) DEBUG_PRINT(" found=%d len=%d idx=%d ch=%d max=%f", - found, st->group.len, st->group.max_idx, st->group.max_ch, st->group.max); - /* end */ if (found) { /* Continue ongoing group */ @@ -117,8 +118,9 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) { return; /* A group ended. Process result. */ - DEBUG_PRINT("GROUP FOUND: %8d len=%3d max=%f ch=%d offx=%d", - sim_pos, st->group.len, st->group.max, st->group.max_ch, st->group.max_idx); + if (record_channel == -1) + DEBUG_PRINT("GROUP FOUND: %8d len=%3d max=%f ch=%d offx=%d", + sim_pos, st->group.len, st->group.max, st->group.max_ch, st->group.max_idx); /* reset grouping state */ st->group.len = 0; diff --git a/controller/fw/src/dsss_demod.h b/controller/fw/src/dsss_demod.h index 8ab5cac..b6947bc 100644 --- a/controller/fw/src/dsss_demod.h +++ b/controller/fw/src/dsss_demod.h @@ -36,7 +36,7 @@ struct dsss_demod_state { }; #ifdef SIMULATION -void dsss_demod_step(struct dsss_demod_state *st, float new_value, size_t sim_pos); +void dsss_demod_step(struct dsss_demod_state *st, float new_value, size_t sim_pos, int record_channel); #else /* SIMULATION */ void dsss_demod_step(struct dsss_demod_state *st, float new_value); #endif /* SIMULATION */ -- cgit