summaryrefslogtreecommitdiff
path: root/controller/fw/tools
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-06 11:54:33 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-03-06 11:54:33 +0100
commite4693349cf862f8c609a0a7586b24d703486fff9 (patch)
tree4cf8a458782b18c55ca4ef182f5888c69b5ac700 /controller/fw/tools
parentad9e17c35c2fc358e6660d179c844b14b92c5541 (diff)
downloadmaster-thesis-e4693349cf862f8c609a0a7586b24d703486fff9.tar.gz
master-thesis-e4693349cf862f8c609a0a7586b24d703486fff9.tar.bz2
master-thesis-e4693349cf862f8c609a0a7586b24d703486fff9.zip
Correlator seems to be working
Diffstat (limited to 'controller/fw/tools')
-rw-r--r--controller/fw/tools/butter_filter_gen.py20
1 files changed, 17 insertions, 3 deletions
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()