From f382efe609f049c7e78171a76e9d0c550521958b Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 26 Aug 2014 17:24:55 +0300 Subject: [PATCH] dsp: Filter should hold processing state --- amodem/dsp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/amodem/dsp.py b/amodem/dsp.py index 8037f12..45e1f91 100644 --- a/amodem/dsp.py +++ b/amodem/dsp.py @@ -13,10 +13,12 @@ class Filter(object): def __init__(self, b, a): self.b = np.array(b) / a[0] self.a = np.array(a[1:]) / a[0] + self.x_state = [0] * len(self.b) + self.y_state = [0] * (len(self.a) + 1) + def __call__(self, x): - x_ = [0] * len(self.b) - y_ = [0] * (len(self.a) + 1) + x_, y_ = self.x_state, self.y_state for v in x: x_ = [v] + x_[:-1] y_ = y_[:-1] @@ -25,6 +27,7 @@ class Filter(object): y = num - den y_ = [y] + y_ yield y + self.x_state, self.y_state = x_, y_ def lfilter(b, a, x):