-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
61 lines (44 loc) · 1.07 KB
/
example.py
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
# %%
import scipy.signal
import signal
import sys
import data
import fdls
import matplotlib
gui_env = ['TKAgg', 'GTKAgg', 'Qt4Agg', 'WXAgg']
for gui in gui_env:
try:
print("Testing backend: ", gui)
matplotlib.use(gui, warn=False, force=True)
from matplotlib import pyplot as plt
break
except:
continue
print("Using:", matplotlib.get_backend())
# %%
plt.figure(1)
plt.title("Discretized linear frequency response")
plt.plot(data.frequency, data.amplitude)
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")
# plt.show()
# %%
b, a = fdls.fdls(data.frequency, data.amplitude, data.phase, fs=1000)
w, h = scipy.signal.freqz(b, a)
# %%
plt.figure(2)
plt.title('Continuous digital filter frequency response')
plt.plot(w, h)
plt.ylabel('Amplitude')
plt.xlabel('Frequency (Hz)')
plt.grid()
# %%
# Must register singal handler before showing plot, enters TKAgg event loop
def handler(signum, frame):
print('Quitting')
try:
plt.close()
finally:
sys.exit(0)
signal.signal(signal.SIGINT, handler)
plt.show()