mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 01:18:02 +08:00
fix sigproc.Filter
This commit is contained in:
@@ -16,11 +16,14 @@ class Filter(object):
|
||||
|
||||
def __call__(self, x):
|
||||
x_ = [0] * len(self.b)
|
||||
y_ = [0] * len(self.a)
|
||||
y_ = [0] * (len(self.a) + 1)
|
||||
for v in x:
|
||||
x_ = [v] + x_[:-1]
|
||||
y = np.dot(x_, self.b) - np.dot(y_, self.a)
|
||||
y_ = [y] + y_[1:]
|
||||
y_ = y_[:-1]
|
||||
num = np.dot(x_, self.b)
|
||||
den = np.dot(y_, self.a)
|
||||
y = num - den
|
||||
y_ = [y] + y_
|
||||
yield y
|
||||
|
||||
|
||||
|
||||
@@ -23,3 +23,15 @@ def test_linreg():
|
||||
a_, b_ = sigproc.linear_regression(x, y)
|
||||
assert abs(a - a_) < 1e-10
|
||||
assert abs(b - b_) < 1e-10
|
||||
|
||||
|
||||
def test_filter():
|
||||
f = sigproc.Filter(b=[1], a=[1])
|
||||
x = range(10)
|
||||
y = list(f(x))
|
||||
assert [float(i) for i in x] == y
|
||||
|
||||
f = sigproc.Filter(b=[0.5], a=[1, -0.5])
|
||||
x = [1] + [0] * 10
|
||||
y = list(f(x))
|
||||
assert y == [0.5 ** (i+1) for i in range(len(x))]
|
||||
|
||||
Reference in New Issue
Block a user