且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python中的带通滤波器

更新时间:2022-10-15 15:50:24

尝试过滤采样率不一致的数据非常困难(不可能?).所以你要做的是:

  1. 创建一个具有固定采样率的新信号.固定采样率应为最大采样率或更高.通过设置一个新的网格"来表示新样本应该去哪里,并从现有数据中插入它们的值来做到这一点.存在多种插值方法,具体取决于您需要的准确度.线性插值可能不是一个糟糕的起点,但这取决于您在做什么.如果您不确定,请咨询 https://dsp.stackexchange.com/.

  2. 完成此操作后,您可以对信号应用标准信号处理方法,因为样本是均匀放置的,例如您链接的帖子中描述的那些.

  3. 如有必要,您可能需要再次插值以恢复原始样本位置.

如果您只想分析数据,您可能会对 Lomb Periodigram.您可以使用 Lomb Periodigram,而不是带通数据然后进行分析,然后只查看相关频率,或者根据需要对结果进行加权.(另请参阅数值食谱系列.第 13.8 章称为不均匀间隔数据的光谱分析",这似乎是比***页面更友好的介绍)

​​>

I'm trying to get a bandpass filter with a 128-point Hamming window with cutoff frequencies 0.7-4Hz in python. I get my samples for my signal from images. (1 sample = 1 image). The fps often changes.

How can this be done in python? I read this: http://mpastell.com/2010/01/18/fir-with-scipy/ but I find firwin rather confusing. How can this be done with this variable fps?

Trying to filter data with an inconsistent sample rate is very difficult (impossible?). So what you are going to want to do is this:

  1. Create a new signal with a fixed sample rate. The fixed sample rate should be the maximum sample rate or higher. Do this by setting up a new "grid" representing where the new samples should go, and interpolating their values from existing data. A variety of interpolation methods exist depending on how accurate you need to be. Linear interpolation is probably not a bad starting point, but it depends on what you are doing. Ask on https://dsp.stackexchange.com/ if you are unsure.

  2. Once you've done that, you can apply standard signal processing methods to your signal because the samples are evenly placed, such as those described in the post you linked.

  3. If necessary, you may need to interpolate again to get your original sample positions back.

If you are looking only to analyze your data, you might be interested in the Lomb Periodigram. Instead of band-passing your data and then analyzing, you would use the Lomb Periodigram, and then only look at the relevant frequencies, or weight the results however you wanted. (see also the numerical recipes series. Chapter 13.8 is called "Spectral analysis of unevenly spaced data", which appears to be a friendlier introduction than that wikipedia page)