[SciPy-user] butter function different from matlab?

Nils Wagner nwagner at iam.uni-stuttgart.de
Thu Aug 9 09:06:06 EDT 2007


Will Woods wrote:
> I'm rather new to the scipy.signal module, so I appologise if I have 
> missed something obvious, but I seem to be getting strange results from 
> the 'butter' function.
>
> In matlab, a 9th order higpass filter at 300 Hz on a signal sampled at 
> 1kHz would be:
>
>  >> [B,A] = butter(9,300/500,'high')
>
> B =
>
>      0.0011   -0.0096    0.0384   -0.0895    0.1342   -0.1342    0.0895 
>    -0.0384    0.0096   -0.0011
>
>
> A =
>
>      1.0000    1.7916    2.5319    2.1182    1.3708    0.6090    0.1993 
>     0.0431    0.0058    0.0004
>
>
>
>
> If I do the same with scipy.signal.butter, I get:
>
> In [47]: (b,a)=butter(9,300/500,btype='high')
>
> In [48]: (b,a)
> Out[48]:
> (array([   1.,   -9.,   36.,  -84.,  126., -126.,   84.,  -36.,    9., 
> -1.]),
>   array([   1.,   -9.,   36.,  -84.,  126., -126.,   84.,  -36.,    9., 
>    -1.]))
>
>
> It would seem that b is roughly 1000 * B, and that a is the same as b, 
> while in matlab B and A are very different.
>
> Can anyone explain why this is? The docs for matlab butter function 
> appear to say the same thing as the scipy version.
>
> Thanks
>
> Will
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   
Please note that 300/500 is zero. You may use

>>> (b,a)=signal.butter(9,300./500,btype='high')
>>> b
array([ 0.00106539, -0.00958855,  0.0383542 , -0.08949314,  0.13423971,
       -0.13423971,  0.08949314, -0.0383542 ,  0.00958855, -0.00106539])
>>> a
array([  1.00000000e+00,   1.79158135e+00,   2.53189988e+00,
         2.11822942e+00,   1.37075629e+00,   6.09038913e-01,
         1.99331557e-01,   4.31047310e-02,   5.80426165e-03,
         3.55580604e-04])

>>> 300/500
0
>>> 300./500
0.59999999999999998
>>>                 

Nils

 




More information about the SciPy-User mailing list