Created
November 7, 2011 15:32
-
-
Save nicolamontecchio/1345284 to your computer and use it in GitHub Desktop.
quick (almost-untested) hack - linear filter in python (uses numpy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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