Working on DSSS demodulator sim
This commit is contained in:
parent
d9b26d16c0
commit
4b419bd1ad
14 changed files with 94312 additions and 62 deletions
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import math
|
||||
import textwrap
|
||||
import contextlib
|
||||
|
||||
import numpy as np
|
||||
import scipy.signal as sig
|
||||
|
|
@ -24,22 +27,50 @@ def gold(n):
|
|||
(seq0, _st0), (seq1, _st1) = sig.max_len_seq(n, taps=t0), sig.max_len_seq(n, taps=t1)
|
||||
return gen_gold(seq0, seq1)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def print_include_guards(macro_name):
|
||||
print(f'#ifndef {macro_name}')
|
||||
print(f'#define {macro_name}')
|
||||
yield
|
||||
print(f'#endif /* {macro_name} */')
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
parser.add_argument('n', type=int, choices=preferred_pairs, help='bit width of shift register. Generate 2**n + 1 sequences of length 2**n - 1.')
|
||||
parser.add_argument('-v', '--variable', default='gold_code_table', help='Name for weak alias of generated table')
|
||||
parser.add_argument('-h', '--header', action='store_true', help='Generate header file')
|
||||
parser.add_argument('-c', '--source', action='store_true', help='Generate table source file')
|
||||
args = parser.parse_args()
|
||||
|
||||
print('#include <unistd.h>')
|
||||
print()
|
||||
print(f'/* {args.n} bit gold sequences: {2**args.n+1} sequences of length {2**args.n-1} bit.')
|
||||
print(f' *')
|
||||
print(f' * Each code is packed left-aligned into {2**args.n // 8} bytes in big-endian byte order.')
|
||||
print(f' */')
|
||||
print(f'const uint8_t gold_code_{args.n}bit[] = {{')
|
||||
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 gold_code_table __attribute__((weak)) = gold_code_{args.n}bit;')
|
||||
if not args.header != args.source:
|
||||
print('Exactly one of --header and --source must be given.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
nbytes = math.ceil((2**args.n-1)/8)
|
||||
|
||||
if args.source:
|
||||
print('/* THIS IS A GENERATED FILE. DO NOT EDIT! */')
|
||||
print('#include <unistd.h>')
|
||||
print('#include <stdint.h>')
|
||||
print()
|
||||
print(f'/* {args.n} bit gold sequences: {2**args.n+1} sequences of length {2**args.n-1} bit.')
|
||||
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}] = {{')
|
||||
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