简体   繁体   English

python中的低通滤波器

[英]Lowpass Filter in python

I am trying to convert a Matlab code to Python. 我正在尝试将Matlab代码转换为Python。 I want to implement fdesign.lowpass() of Matlab in Python. 我想在Python中实现Matlab的fdesign.lowpass() What will be the exact substitute of this Matlab code using scipy.signal.firwin() : 使用scipy.signal.firwin() ,这个Matlab代码的确切替代品是什么:

demod_1_a = mod_noisy * 2.*cos(2*pi*Fc*t+phi);
d = fdesign.lowpass('N,Fc', 10, 40, 1600);
Hd = design(d);
y = filter(Hd, demod_1_a);

A very basic approach would be to invoke 一种非常基本的方法是调用

# spell out the args that were passed to the Matlab function
N = 10
Fc = 40
Fs = 1600
# provide them to firwin
h = scipy.signal.firwin(numtaps=N, cutoff=40, nyq=Fs/2)
# 'x' is the time-series data you are filtering
y = scipy.signal.lfilter(h, 1.0, x)

This should yield a filter similar to the one that ends up being made in the Matlab code. 这应该产生一个类似于最终在Matlab代码中制作的过滤器。 If your goal is to obtain functionally equivalent results, this should provide a useful filter. 如果你的目标是获得功能相同的结果,这应该提供一个有用的过滤器。

However, if your goal is that the python code provide exactly the same results, then you'll have to look under the hood of the design call (in Matlab); 但是,如果你的目标是python代码提供完全相同的结果,那么你将不得不深入研究design调用(在Matlab中); From my quick check, it's not trivial to parse through the Matlab calls to identify exactly what it is doing, ie what design method is used and so on, and how to map that into corresponding scipy calls. 从我的快速检查中,解析Matlab调用以确切地识别它正在做什么,即使用什么设计方法等等,以及如何将其映射到相应的scipy调用中并scipy If you really want compatibility, and you only need to do this for a limited number of filters, you could, by hand, look at the Hd.Numerator field -- this array of numbers directly corresponds to the h variable in the python code above. 如果你真的想要兼容性,并且只需要为有限数量的过滤器执行此操作,您可以手动查看Hd.Numerator字段 - 这个数字数组直接对应于上面python代码中的h变量。 So if you copy those numbers into an array by hand, you'll get numerically equivalent results. 因此,如果您手动将这些数字复制到数组中,您将获得数值相同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM