-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
73 lines (50 loc) · 1.52 KB
/
__main__.py
File metadata and controls
73 lines (50 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from sys import exit
from nonumpy import Factory as NonumpyFactory
from crelm import Factory as CrelmFactory
# todo foss: move this into John
def make_plotter(min: float, max: float, width: int):
source = f'''
#include <stdio.h>
void plot(int x, float y)
{{
char p = '*';
float v = y - {min};
v *= (float){width} / ({max} - {min});
int j = (int)v;
if (j < 0)
{{
j = 0;
p = '<';
}}
else if (j >= {width})
{{
j = {width} - 1;
p = '>';
}}
char s[{width + 1}];
for (int i = 0; i < {width}; ++i)
{{
s[i] = j == i ? p : ({width} / 2 == i ? '|' : '.');
}}
s[{width}] = 0;
printf("(%3d, % f) %s\\n", x, y, s);
}}
'''
return CrelmFactory().create_Tube('plotter') \
.add_source_text(source) \
.squeeze()
def plot(filter, plotter):
plotter.plot(0, filter.run(1))
for x in range(1, 50):
plotter.plot(x, filter.run(0))
if '__main__' == __name__:
print('building plotter...')
plotter = make_plotter(min=-0.1, max=0.1, width=60)
filter_parms = {'cutoff_hz': 1, 'order': 2, 'sample_rate_hz': 25}
print('building low pass Butterworth...')
plot(NonumpyFactory().create_FilterLowPassButterworth(**filter_parms), plotter)
print('building high pass Butterworth...')
plot(NonumpyFactory().create_FilterHighPassButterworth(**filter_parms), plotter)
print('building Exponential Moving Average...')
plot(NonumpyFactory().create_EMA(alpha=0.1), plotter)
exit(42)