Transform filter function to Python code
Question: I'm trying to understand how to transform a filter, in this case a
Notch(stopband) filter, to Python but I don't know how.

    
    
    x(n)=-2*x(n)/(-0.9*x(n) -0.9*x(n-1))
    

Can anyone help me please?

Thanks in advance.


Answer: If you're using numpy arrays, this should work:

    
    
    x[1:]=-2*x[1:]/(-0.9*x[1:]-0.9*x[:-1])
    

this changes your array in place, but you could just as easily assign it to a
new array.

    
    
    y=-2*x[1:]/(-0.9*x[1:]-0.9*x[:-1])
    

Note that your algorithm isn't really well defined for the 0th element, so my
translation leaves `x[0]` unchanged.

**EDIT**

To change an iterable to a numpy array:

    
    
    import numpy as np
    x=np.array(iterable)  #pretty easy :) although there could be more efficient ways depending on where "iterable" comes from.
    

