Skip to content

Instantly share code, notes, and snippets.

@nicolamontecchio
Created November 7, 2011 15:32
Show Gist options
  • Select an option

  • Save nicolamontecchio/1345284 to your computer and use it in GitHub Desktop.

Select an option

Save nicolamontecchio/1345284 to your computer and use it in GitHub Desktop.
quick (almost-untested) hack - linear filter in python (uses numpy)
class Filter(object):
""" Linear Filter, notation is similar to matlab's filter function """
def __init__(self, b, a, xinit, yinit):
self.b = np.array(b)
self.a = np.array(a)
self.x = np.array(xinit)[::-1]
self.y = np.array(yinit)[::-1]
def tick(self, x) :
self.x = np.hstack((x,self.x[:-1]))
y = sum(self.b * self.x[:len(self.b)])
y -= sum(self.a[1:] * self.y[:len(self.a)-1])
y /= self.a[0]
self.y = np.hstack((y,self.y[:-1]))
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment