Python中的滤波器设计和频率提取 [英] Filter design and frequency extraction in Python

查看:397
本文介绍了Python中的滤波器设计和频率提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中寻找Python中多分量音频信号的瞬时频率.我目前正在将Butterworth带通滤波器与scipy.signal.lfilter结合使用,以在所需的频率范围内进行提取.然后,我使用来自scipy.signal.hilbert的分析信号来获取瞬时相位,可以将其展开以给出频率.

I'm working on a project to find the instantaneous frequency of a multicomponent audio signal in Python. I am currently using a Butterworth bandpass filter combined with scipy.signal.lfilter to extract around my desired frequency region. I then use the analytic signal (from scipy.signal.hilbert) to get the instantaneous phase, which can be unwrapped to give frequency.

作为信号处理的相对新手,我有两个主要问题:

As a relative novice to signal processing, I have two main questions:

  1. 我已阅读到在许多应用程序中,最好使用scipy.signal.filtfilt而不是scipy.signal.lfilter.当然,当我对数据应用filtfilt时,我会得到一个看起来更加平滑的瞬时频率信号.我想知道两者之间的主要区别,请记住我想要获得尽可能接近真实"瞬时频率的输出.

  1. I have read that in many applications, it is preferable to use scipy.signal.filtfilt over scipy.signal.lfilter. Certainly when I apply filtfilt to my data, I get a significantly smoother looking instantaneous frequency signal. I would like to know the major differences between the two, bearing in mind that I would like to get an output which is as close to the "true" instantaneous frequency as possible.

瞬时频率数据是不稳定的,这意味着在某些情况下,我必须使用更宽的带通滤波器来捕获所有所需的数据.这似乎给我的信号带来了额外的噪声和偶尔的不稳定性.有没有办法解决这类问题,例如设计更好的过滤器?

The instantaneous frequency data is nonstationary, which means that in some instances I must use a wider bandpass filter to capture all my desired data. This appears to introduce additional noise, and occassional instabilities, into my signal. Are there ways to deal with these kinds of problems, for example with a better designed filter?

编辑

为回应flebool,以下是我正在查看的数据的一些图像.首先,比较filtfiltfilt: 的比较 以上两个信号都应用了相同的巴特沃思滤波器(尽管滤波器功能不同),然后提取了瞬时频率(它是随时间变化的曲线图). filtfilt似乎可以移动和平滑数据.这些信号之一是真实"信号的更好近似吗?

In response to flebool, below are some images of the data I am looking at. First, a comparison of filt and filtfilt: Both the above signals have had the same Butterworth filter applied (although the filter function is different), followed by extraction of instantaneous frequency (which is what is plotted, as a function of time). filtfilt seems to shift and smooth the data. Is one of these signals a better approximation of the "true" signal?

请注意,此图仅显示特定信号的子集.

Note that this graph shows just a subset of a particular signal.

第二,增加巴特沃斯滤镜尺寸的效果: 这是与图1相同的数据子集.图例分别显示了过滤器的上限和下限(红色轨迹是图1中数据的filt版本).

Second, the effect of increasing the Butterworth filter size: This is for the same subset of data as figure 1. The legend shows the lower and upper bound for the filter, respectively (the red trace is the filt version of the data in figure 1).

尽管在此处可能不清楚我为什么要使用较大的通带,但在某些情况下,数据可能位于600Hz和800Hz之间的各个点.在这里,我需要更广泛的滤波器设计.您会看到,随着滤波器的变宽,额外的噪声会进入轨迹.我想知道是否有一种方法可以优化/改进我的滤波器设计.

Although it may not be clear here why I would use a larger pass band, in some instances the data may be located at various points between, say, 600 and 800Hz. It is here that I would require a broader filter design. You can see that additional noise enters the trace as the filter gets wider; I'd like to know if there's a way to optimise/improve my filter design.

推荐答案

一些稀疏注释:

1)在最上面的图片:尽管filtfilt的频率变化令人担忧,但我无法评论filtfilt和filtfilt之间的最佳组合.通过对滤波信号应用低通滤波器,可以获得类似的结果.

1) On the top picture: I can't comment on what is best between filt and filtfilt, though the shift in frequency of filtfilt is worrying. You can obtain a similar result by applying a low-pass filter to the filt signal.

2)没有真实"的瞬时频率,除非信号是用特定的音调专门产生的.以我的经验,在许多情况下,展开希尔伯特变换的阶段都做得很好.随着噪声与信号强度之比的增加,它变得越来越不可靠.

2) There isn't a "true" instantaneous frequency, unless the signal was specifically generated with a certain tone. In my experience unwrapping the phase of the Hilbert transform does a good job in many cases, though. It becomes less and less reliable as the ratio of noise to signal intensity grows.

3)关于底部图片,您说有时需要一个大的带通滤波器.这是因为信号很长,瞬时频率在500到800 Hz之间波动吗?如果是这样,您可能希望将信号开窗到一定的长度,使滤波后的信号在傅立叶频谱中具有明显的峰值,提取该峰值,针对该峰值调整您的带基滤波器,将希尔伯特应用于开窗信号,提取相位,过滤相位.

3) Regarding the bottom picture, you say that sometimes you need a large bandpass filter. Is this because the signal is very long, and the instantaneous frequency moves around between 500 and 800 Hz? If so, you may want to proceed windowing the signal to a length at which the filtered signal has a distinct peak in the Fourier spectrum, extract that peak, tailor your bandbass filter to that peak, apply Hilbert to the windowed signal, extract the phase, filter the phase.

如果您确定信号除噪声和您感兴趣的谐波以外还有其他谐波,这是值得做的,这需要一段时间.在这样做之前,我想确保我获得的数据是错误的.

This is worth doing if you are sure the signal has other harmonics except noise and the one you are interested in, and it takes a while. Before doing so I would want to be sure the data I obtain is wrong.

如果只是1次谐波+噪声,我将在瞬时相位上再次低通+希尔伯特+提取瞬时相位+低通

If it is simply 1 harmonic + noise, I would lowpass+hilbert+extract instantaneous phase + lowpass again on the instantaneous phase

这篇关于Python中的滤波器设计和频率提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆