<s> import numpy as np <EOL> class IIR ( object ) : <EOL> def __init__ ( self , b , a ) : <EOL> self . b = np . array ( b ) / a [ <NUM_LIT:0> ] <EOL> self . a = np . array ( a [ <NUM_LIT:1> : ] ) / a [ <NUM_LIT:0> ] <EOL> self . x_state = [ <NUM_LIT:0> ] * len ( self . b ) <EOL> self . y_state = [ <NUM_LIT:0> ] * ( len ( self . a ) + <NUM_LIT:1> ) <EOL> def __call__ ( self , x ) : <EOL> x_ , y_ = self . x_state , self . y_state <EOL> for v in x : <EOL> x_ = [ v ] + x_ [ : - <NUM_LIT:1> ] <EOL> y_ = y_ [ : - <NUM_LIT:1> ] <EOL> num = np . dot ( x_ , self . b ) <EOL> den = np . dot ( y_ , self . a ) <EOL> y = num - den <EOL> y_ = [ y ] + y_ <EOL> yield y <EOL> self . x_state , self . y_state = x_ , y_ <EOL> def lfilter ( b , a , x ) : <EOL> f = IIR ( b = b , a = a ) <EOL> y = list ( f ( x ) ) <EOL> return np . array ( y ) </s>
