summaryrefslogtreecommitdiff
path: root/reset-controller/fw/tools/fft_window_header_gen.py
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2021-04-09 18:38:02 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2021-04-09 18:38:57 +0200
commit50998fcfb916ae251309bd4b464f2c122e8cb30d (patch)
tree4ecf7a7443b75ab51c4dc0c0fc9289342dc7d6a0 /reset-controller/fw/tools/fft_window_header_gen.py
parent312fee491cfab436d52db4b6265107e20f3e1293 (diff)
downloadmaster-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.tar.gz
master-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.tar.bz2
master-thesis-50998fcfb916ae251309bd4b464f2c122e8cb30d.zip
Repo re-org
Diffstat (limited to 'reset-controller/fw/tools/fft_window_header_gen.py')
-rw-r--r--reset-controller/fw/tools/fft_window_header_gen.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/reset-controller/fw/tools/fft_window_header_gen.py b/reset-controller/fw/tools/fft_window_header_gen.py
new file mode 100644
index 0000000..7df2ee3
--- /dev/null
+++ b/reset-controller/fw/tools/fft_window_header_gen.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+import textwrap
+
+import scipy.signal as sig
+import numpy as np
+
+WINDOW_TYPES = [
+ 'boxcar',
+ 'triang',
+ 'blackman',
+ 'hamming',
+ 'hann',
+ 'bartlett',
+ 'flattop',
+ 'parzen',
+ 'bohman',
+ 'blackmanharris',
+ 'nuttall',
+ 'barthann',
+ 'kaiser',
+ 'gaussian',
+ 'general_gaussian',
+ 'slepian',
+ 'dpss',
+ 'chebwin',
+ 'exponential',
+ 'tukey',
+ ]
+
+if __name__ == '__main__':
+ import argparse
+ parser = argparse.ArgumentParser()
+ parser.add_argument('window', choices=WINDOW_TYPES, help='Type of window function to use')
+ parser.add_argument('n', type=int, help='Width of window in samples')
+ parser.add_argument('window_args', nargs='*', type=float,
+ help='''Window argument(s) if required. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.get_window.html#scipy.signal.get_window for details.''')
+ parser.add_argument('-v', '--variable', default='fft_window_table', help='Name for alias variable pointing to generated window')
+ args = parser.parse_args()
+
+ print(f'/* FTT window table for {args.n} sample {args.window} window.')
+ if args.window_args:
+ print(f' * Window arguments were: ({" ,".join(str(arg) for arg in args.window_args)})')
+ print(f' */')
+ winargs = ''.join(f'_{arg:.4g}'.replace('.', 'F') for arg in args.window_args)
+ varname = f'fft_{args.n}_window_{args.window}{winargs}'
+ print(f'const float {varname}[{args.n}] = {{')
+
+ win = sig.get_window(args.window if not args.window_args else (args.window, *args.window_args),
+ Nx=args.n, fftbins=True)
+ par = ' '.join(f'{f:>013.8g},' for f in win)
+ print(textwrap.fill(par,
+ initial_indent=' '*4, subsequent_indent=' '*4,
+ width=120,
+ replace_whitespace=False, drop_whitespace=False))
+ print('};')
+ print()
+ print(f'const float * const {args.variable} __attribute__((weak)) = {varname};')
+