在BeagleBone Black上使用numpy(不是scipy!)编程一个butterworth过滤器

时间:2021-05-28 21:25:54

I am a new user of Python and an amateur programmer in general - I am hoping to be able to filter a signal using just the numpy library. It will be programmed onto a BeagleBone Black and the OS is Angstrom Linux, so the furthest numpy library it will update to is 1.4 and due to either rumored data limitations (I am not actually sure how to check) or just the version of numpy being too early, scipy will not work on the board.

我是Python的新用户和一般的业余程序员 - 我希望能够使用numpy库过滤信号。它将被编程到BeagleBone Black上,操作系统是Angstrom Linux,所以它将更新到最远的numpy库是1.4并且由于传闻数据限制(我实际上不确定如何检查)或者只是numpy版本太早,scipy将不会在董事会上工作。

So the first solution is to get a new operating system but I would not know where to start; I am more comfortable in the realm of putting equations into a program.

所以第一个解决方案是获得一个新的操作系统,但我不知道从哪里开始;在将方程式放入程序中我更为舒适。

I was hoping to use the filtfilt function but maybe it would be best to start with lfilter. This site seemed helpful for implementing it but it is a bit beyond me: http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.signal.lfilter.html
I am capable of getting the filter coefficients in MATLAB then transferring them to the BeagleBone. The x is just the array that is my signal which I can upload.

我希望使用filtfilt函数,但也许最好从lfilter开始。这个网站似乎对实现它很有帮助,但它有点超出我的想法:http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.signal.lfilter.html我有能力获得在MATLAB中过滤系数然后将它们传送到BeagleBone。 x只是我可以上传的信号数组。

The second section is a bit of a jump - so is there a way to perform a z-transform in just numpy, not scipy? Also, based on all of the secrecy of the filter algorithm in MATLAB, I do not have faith in working that out, but is there some sort of mathematical algorithm description, or better yet code, describing how I may accomplish this?

第二部分有点跳 - 所以有没有办法在numpy中执行z变换,而不是scipy?另外,基于MATLAB中滤波器算法的所有保密性,我没有信心解决这个问题,但是有没有某种数学算法描述,或者更好的代码,描述我如何实现这一点?

Thanks for your patience in reading through this and the response. Please do not use complicated language in the response!

感谢您耐心阅读本文和回复。请不要在回复中使用复杂的语言!

-Rob

-抢

1 个解决方案

#1


0  

For the filter design functions, you can copy the code from sicpy.signal.filter_design.py, they are almost pure python code.

对于过滤器设计函数,您可以从sicpy.signal.filter_design.py复制代码,它们几乎是纯Python代码。

But to do lfilter for IIR filters, you need a for loop for every sample in the data array. Since for loop in Python is slow, I think you need to implement it in C, and call it throught ctypes. Do you have a c compile in the target machine?

但要为IIR滤波器执行lfilter,您需要为数据数组中的每个样本提供一个for循环。因为Python中的循环很慢,我认为你需要在C中实现它,并通过ctypes调用它。你在目标机器上有c编译吗?

If you can design your filter as a FIR filter, then you can use numpy.convolve(b, x).

如果您可以将滤波器设计为FIR滤波器,则可以使用numpy.convolve(b,x)。

#1


0  

For the filter design functions, you can copy the code from sicpy.signal.filter_design.py, they are almost pure python code.

对于过滤器设计函数,您可以从sicpy.signal.filter_design.py复制代码,它们几乎是纯Python代码。

But to do lfilter for IIR filters, you need a for loop for every sample in the data array. Since for loop in Python is slow, I think you need to implement it in C, and call it throught ctypes. Do you have a c compile in the target machine?

但要为IIR滤波器执行lfilter,您需要为数据数组中的每个样本提供一个for循环。因为Python中的循环很慢,我认为你需要在C中实现它,并通过ctypes调用它。你在目标机器上有c编译吗?

If you can design your filter as a FIR filter, then you can use numpy.convolve(b, x).

如果您可以将滤波器设计为FIR滤波器,则可以使用numpy.convolve(b,x)。