-
Notifications
You must be signed in to change notification settings - Fork 0
/
filtry.py
107 lines (56 loc) · 1.68 KB
/
filtry.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 16 11:32:41 2018
@author: mkrej
"""
from numpy import array, ones
import matplotlib.pyplot as plt
from scipy.signal import lfilter, lfilter_zi, butter, lfiltic
from scipy import signal
import numpy as np
from sos_tests import fparam
b, a = butter(2, 0.001, btype='high')
a
b
zi2 = lfiltic(b, a, y = np.repeat(0, 30), x = np.repeat(1, 30) * 1001)
zi2
zi1 = lfilter_zi(b, a)*1001
zi1
butter()
np.arange(8) / 8
array
sos = butter(2, 0.001, btype='high', output='sos')
x = 1000 + np.arange(1, 5000) % 100
plt.plot(x)
# x = signal.unit_impulse(700)
y_sos = signal.sosfilt(sos, x)
plt.plot(y_sos)
t = np.arange(1,5000)
y_sos_ic = signal.sosfilt(sos, x, zi=np.mat(zi1))
plt.plot(t, y_sos,'r', t, y_sos_ic[0],'b')
#np.size(y_sos)
#plt.show()
from scipy import linalg
linalg.companion(a)
IminusA = np.eye(2) - linalg.companion(a).T
b[1:]
sos = butter(2, [0.002, 0.016], btype='pass', output='sos')
signal.sosfilt_zi(sos)*x[0]
a = [1, -2, 1]
b = [1.0000000, -1.9917666, 0.9918145]
lfilter_zi(b, a)
lfilter_zi(a, b)
lfilter_zi(sos[1,:3], sos[1,3:])
#------------------------------------
# Python
import numpy as np
from scipy import signal
fsamp = 1000 / 8
fparam = 4.0
sos = signal.butter(5, fparam / fsamp * 2, output='sos')
zi0 = signal.sosfilt_zi(sos)
for row in sos:
print("new[] {{ {} }},".format(", ".join("{}".format(x) for x in np.append(row, [1., 1.]) )))
for row in zi0:
print("new[] {{ {} }},".format(", ".join("{}".format(x) for x in row )))
np.append(row, [1., 1.])