WIP DSSS decoding
This commit is contained in:
parent
4b419bd1ad
commit
ad9e17c35c
18 changed files with 578 additions and 31753 deletions
50
controller/fw/tools/butter_filter_gen.py
Normal file
50
controller/fw/tools/butter_filter_gen.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import contextlib
|
||||
|
||||
import scipy.signal as sig
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def wrap(left='{', right='}', file=None, end=''):
|
||||
print(left, file=file, end=end)
|
||||
yield
|
||||
print(right, file=file, end=end)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def print_include_guards(macro_name):
|
||||
print(f'#ifndef {macro_name}')
|
||||
print(f'#define {macro_name}')
|
||||
yield
|
||||
print(f'#endif /* {macro_name} */')
|
||||
|
||||
macro_float = lambda f: f'{f}'.replace('.', 'F').replace('-', 'N').replace('+', 'P')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-m', '--macro-name', default='butter_filter', help='Prefix for output macro names')
|
||||
parser.add_argument('fc', type=float, help='Corner frequency [Hz]')
|
||||
parser.add_argument('fs', type=float, help='Sampling rate [Hz]')
|
||||
parser.add_argument('n', type=int, nargs='?', default=6, help='Filter order')
|
||||
args = parser.parse_args()
|
||||
|
||||
sos = sig.butter(args.n, args.fc, fs=args.fs, output='sos')
|
||||
|
||||
print('/* THIS IS A GENERATED FILE. DO NOT EDIT! */')
|
||||
with print_include_guards(f'__BUTTER_FILTER_GENERATED_{args.n}_{macro_float(args.fc)}_{macro_float(args.fs)}__'):
|
||||
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:
|
||||
with wrap():
|
||||
print('.b=', end='')
|
||||
with wrap():
|
||||
print(', '.join(f'{v}' for v in sec[:3]), end='')
|
||||
print(', .a=', end='')
|
||||
with wrap():
|
||||
print(', '.join(f'{v}' for v in sec[4:6]), end='')
|
||||
print(', ', end='')
|
||||
print()
|
||||
|
|
@ -58,19 +58,13 @@ if __name__ == '__main__':
|
|||
print(f' *')
|
||||
print(f' * Each code is packed left-aligned into {nbytes} bytes in big-endian byte order.')
|
||||
print(f' */')
|
||||
print(f'const uint8_t gold_code_{args.n}bit[{2**args.n+1}][{nbytes}] = {{')
|
||||
print(f'const uint8_t {args.variable}[{2**args.n+1}][{nbytes}] = {{')
|
||||
for i, code in enumerate(gold(args.n)):
|
||||
par = '{' + ' '.join(f'0x{d:02x},' for d in np.packbits(code)) + f'}}, /* {i: 3d} "{"".join(str(x) for x in code)}" */'
|
||||
print(textwrap.fill(par, initial_indent=' '*4, subsequent_indent=' '*4, width=120))
|
||||
print('};')
|
||||
print()
|
||||
print(f'const uint8_t * const {args.variable} __attribute__((weak)) = (uint8_t *const)gold_code_{args.n}bit;')
|
||||
print(f'const size_t {args.variable}_nbits __attribute__((weak)) = {args.n};')
|
||||
else:
|
||||
print('/* THIS IS A GENERATED FILE. DO NOT EDIT! */')
|
||||
with print_include_guards(f'__GOLD_CODE_GENERATED_HEADER_{args.n}__'):
|
||||
print(f'extern const uint8_t gold_code_{args.n}bit[{2**args.n+1}][{nbytes}];')
|
||||
|
||||
with print_include_guards(f'__GOLD_CODE_GENERATED_HEADER_GLOBAL_SYM_{args.variable.upper()}__'):
|
||||
print(f'extern const uint8_t {args.variable}[{2**args.n+1}][{nbytes}];')
|
||||
print(f'extern const size_t {args.variable}_nbits;')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue