-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinuousiir.py
32 lines (26 loc) · 1.01 KB
/
continuousiir.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
from osibase import OsiBase
from scipy.signal import butter, lfilter, freqz
## Filter data along one-dimension with an IIR or FIR filter.
# Guarantees same output regardless of chunking of input samples
class ContinuousIIR(OsiBase):
## Constructor
# @param b B Coefficients
# @param a A Coefficients
def __init__(self, b, a):
super(ContinuousIIR, self).__init__()
self.b = b ##! B Coefficients
self.a = a ##! A Coefficients
self.zf = None ##! Stored taps from previous samples
assert len(b) == len(a) or (len(b) != len(a) and len(a) == 1)
## Not used
def rxdown(self, data, meta=False):
print("not used")
## Receive data from up
def rxup(self, data, meta=False):
# when self.zf is none, use zeros
if self.zf is None:
y, self.zf = lfilter(self.b, self.a, data, -1, [0]*(len(self.b)-1) )
else:
y, self.zf = lfilter(self.b, self.a, data, -1, self.zf)
# print self.zf
self.txdown(y)