From e4693349cf862f8c609a0a7586b24d703486fff9 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 6 Mar 2020 11:54:33 +0100 Subject: Correlator seems to be working --- controller/fw/Makefile | 6 +++--- controller/fw/cmsis | 2 +- controller/fw/libsodium | 2 +- controller/fw/src/dsss_demod.c | 25 +++++++++++++------------ controller/fw/tools/butter_filter_gen.py | 20 +++++++++++++++++--- 5 files changed, 35 insertions(+), 20 deletions(-) (limited to 'controller') diff --git a/controller/fw/Makefile b/controller/fw/Makefile index 6c5d5ea..2c75bbf 100644 --- a/controller/fw/Makefile +++ b/controller/fw/Makefile @@ -51,11 +51,11 @@ FMEAS_SAMPLING_RATE ?= 10.0 DSSS_GOLD_CODE_NBITS ?= 5 DSSS_DECIMATION ?= 10 -DSSS_THESHOLD_FACTOR ?= 4.0f +DSSS_THESHOLD_FACTOR ?= 5.0f DSSS_WAVELET_WIDTH ?= 7.3 DSSS_WAVELET_LUT_SIZE ?= 69 -DSSS_FILTER_FC ?= 20e-3 -DSSS_FILTER_ORDER ?= 8 +DSSS_FILTER_FC ?= 10e-3 +DSSS_FILTER_ORDER ?= 10 CC := $(PREFIX)gcc CXX := $(PREFIX)g++ diff --git a/controller/fw/cmsis b/controller/fw/cmsis index 4a65d88..6a86f4c 160000 --- a/controller/fw/cmsis +++ b/controller/fw/cmsis @@ -1 +1 @@ -Subproject commit 4a65d88011a1595b7c8b42fa0d70b7bdfc132acc +Subproject commit 6a86f4ca00d2b96b82879e1e5bd9e89c5750dd22 diff --git a/controller/fw/libsodium b/controller/fw/libsodium index a0a8706..afae623 160000 --- a/controller/fw/libsodium +++ b/controller/fw/libsodium @@ -1 +1 @@ -Subproject commit a0a8706c9dc9e43bc51d16334cd6c0f6ae084ce9 +Subproject commit afae623190f025e7cf2fb0222bfe796b69a36941 diff --git a/controller/fw/src/dsss_demod.c b/controller/fw/src/dsss_demod.c index 7a2e0cc..7feb41b 100644 --- a/controller/fw/src/dsss_demod.c +++ b/controller/fw/src/dsss_demod.c @@ -32,6 +32,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) { //#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; @@ -42,12 +43,16 @@ void dsss_demod_step(struct dsss_demod_state *st, float 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, debug); + st->correlation[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("%8.5f, ", st->correlation[i][st->correlation_wpos]); DEBUG_PRINTN("]\n"); } /* end */ @@ -57,24 +62,20 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) { for (size_t i=0; icorrelation[i], st->correlation_wpos); /* debug */ - /* - if (debug) DEBUG_PRINTN(" cwt: ["); + if (debug) DEBUG_PRINTN(" cwt: ["); for (size_t i=0; icwt_filter[i].st); /* debug */ - /* - DEBUG_PRINTN(" avg: ["); + if (debug) DEBUG_PRINTN(" avg: ["); for (size_t i=0; igroup.max; @@ -150,7 +151,7 @@ float cwt_convolve_step(const float v[DSSS_WAVELET_LUT_SIZE], size_t offx) { sum += v[(offx + j) % DSSS_WAVELET_LUT_SIZE] * dsss_cwt_wavelet_table[j]; //DEBUG_PRINT(" j=%d v=%f w=%f", j, v[(offx + j) % DSSS_WAVELET_LUT_SIZE], dsss_cwt_wavelet_table[j]); } - return sum / DSSS_WAVELET_LUT_SIZE; + return sum; } /* Compute last element of correlation for input [a] and hard-coded gold sequences. diff --git a/controller/fw/tools/butter_filter_gen.py b/controller/fw/tools/butter_filter_gen.py index 059dea0..c77a6ec 100644 --- a/controller/fw/tools/butter_filter_gen.py +++ b/controller/fw/tools/butter_filter_gen.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 +import math import sys import contextlib import scipy.signal as sig +import numpy as np @contextlib.contextmanager @@ -38,13 +40,25 @@ if __name__ == '__main__': print(f'#define {args.macro_name.upper()}_ORDER {args.n}') print(f'#define {args.macro_name.upper()}_CLEN {(args.n+1)//2}') print(f'#define {args.macro_name.upper()}_COEFF ', end='') - for sec in sos: + + # scipy.signal.butter by default returns extremely small bs for the first biquad and large ones for subsequent + # sections. Balance magnitudes to reduce possible rounding errors. + first_biquad_bs = sos[0][:3] + approx_mag = round(math.log10(np.mean(first_biquad_bs))) + mags = [approx_mag // len(sos)] * len(sos) + mags[0] += approx_mag - sum(mags) + sos[0][:3] /= 10**approx_mag + + for mag, sec in zip(mags, sos): + bs, ases = sec[:3], sec[4:6] + bs *= 10**mag + with wrap(): print('.b=', end='') with wrap(): - print(', '.join(f'{v}' for v in sec[:3]), end='') + print(', '.join(f'{v}' for v in bs), end='') print(', .a=', end='') with wrap(): - print(', '.join(f'{v}' for v in sec[4:6]), end='') + print(', '.join(f'{v}' for v in ases), end='') print(', ', end='') print() -- cgit