简体   繁体   English

Python中的滤波器设计和频率提取

[英]Filter design and frequency extraction in Python

I'm working on a project to find the instantaneous frequency of a multicomponent audio signal in Python. 我正在一个项目中,以找到Python中多分量音频信号的瞬时频率。 I am currently using a Butterworth bandpass filter combined with scipy.signal.lfilter to extract around my desired frequency region. 我目前正在将Butterworth带通滤波器与scipy.signal.lfilter结合使用,以提取所需的频率区域附近。 I then use the analytic signal (from scipy.signal.hilbert ) to get the instantaneous phase, which can be unwrapped to give frequency. 然后,我使用解析信号(来自scipy.signal.hilbert )来获取瞬时相位,可以将其展开以给出频率。

As a relative novice to signal processing, I have two main questions: 作为信号处理的相对新手,我有两个主要问题:

  1. I have read that in many applications, it is preferable to use scipy.signal.filtfilt over scipy.signal.lfilter . 我已经读过,在许多应用程序中,最好使用scipy.signal.filtfilt不是scipy.signal.lfilter Certainly when I apply filtfilt to my data, I get a significantly smoother looking instantaneous frequency signal. 当然,当我将filtfilt应用于数据时,我会得到一个看起来更加平滑的瞬时频率信号。 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. 我想知道两者之间的主要区别,请牢记我希望获得尽可能接近“真实”瞬时频率的输出。

  2. 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? 有没有办法解决这类问题,例如设计更好的过滤器?

EDIT 编辑

In response to flebool, below are some images of the data I am looking at. 针对flebool,以下是我正在查看的数据的一些图像。 First, a comparison of filt and filtfilt : 首先,比较filtfiltfilt <code> filt </ code>和<code> filtfilt </ code>的比较 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. filtfilt似乎可以移动和平滑数据。 Is one of these signals a better approximation of the "true" signal? 这些信号之一是“真实”信号的更好近似吗?

Note that this graph shows just a subset of a particular signal. 注意,此图仅显示特定信号的子集。

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). 这是与图1相同的数据子集。图例分别显示了过滤器的上限和下限(红色轨迹是图1中数据的filt版本)。

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. 尽管在此处可能不清楚我为什么要使用较大的通带,但在某些情况下,数据可能位于600和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. 我想知道是否有一种方法可以优化/改进我的滤波器设计。

To your first problem I can't speak intelligently on but scipy is generally well documented so I'd start reading through some of their stuff. 关于您的第一个问题,我不能说得很聪明,但是scipy通常都有据可查,因此我将开始阅读其中的一些内容。

To your second problem a better designed filter would certainly help. 对于您的第二个问题,设计更好的过滤器肯定会有所帮助。 You say the data is "non-stationary," do you know where it will be? 您说数据是“非平稳的”,您知道它将在哪里吗? Or what kind frequencies it might occupy? 或它可能占据哪种频率? For example if the signal is centered around 1 of 3 frequencies that you know a-priori you could have three different filters and run the signal through all 3 (only one giving you the output you want of course). 例如,如果信号以3个频率中的1个为中心(您知道先验频率),则可以使用三个不同的滤波器,并通过所有3个信号运行该信号(当然只有一个可以为您提供所需的输出)。

If you don't know have that kind of knowledge about the signal I would first do a wider BPF, then do some peak detection, and apply a more stringent BPF when you know where the data you would like is located 如果您不了解信号方面的知识,那么我会先做一个较宽的BPF,然后再进行一些峰值检测,并在知道要放置的数据的位置时应用更严格的BPF。

Some sparse comments: 一些稀疏的评论:

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. 1)在上图:尽管filtfilt的频率变化令人担忧,但我无法评论filtfilt和filtfilt之间的最佳组合。 You can obtain a similar result by applying a low-pass filter to the filt signal. 通过对滤波信号应用低通滤波器,可以获得类似的结果。

2) There isn't a "true" instantaneous frequency, unless the signal was specifically generated with a certain tone. 2)没有“真实”的瞬时频率,除非信号是特定音调的。 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) Regarding the bottom picture, you say that sometimes you need a large bandpass filter. 3)关于底部图片,您说有时需要一个大的带通滤波器。 Is this because the signal is very long, and the instantaneous frequency moves around between 500 and 800 Hz? 这是因为信号很长,瞬时频率在500到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. 在这样做之前,我想确保获得的数据是错误的。

If it is simply 1 harmonic + noise, I would lowpass+hilbert+extract instantaneous phase + lowpass again on the instantaneous phase 如果仅仅是1个谐波+噪声,我将在瞬时相位上再次低通+希尔伯特+提取瞬时相位+低通

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

相关问题 如何使用python指定我的截止频率为0.1 Hz来设计Butterworth滤波器? - How can I design a Butterworth filter with python specifying that my cutoff frequency is 0.1 Hz? python中语音特征提取(梅尔频率倒谱系数) - Feature extraction speech (Mel Frequency cepstral coefficient) in python Python PyAudio + mic输入 - 特定的频率滤波器? - Python PyAudio + mic input - specific frequency filter? python特定频率删除(陷波滤波器)? - python specific frequency remove(notch filter)? Python 具有列表设计模式的过滤器 - Python Filter with a design pattern for a list 如何使用 python lib librosa.pyin 获得完整的基本 (f0) 频率提取? - How to get complete fundamental (f0) frequency extraction with python lib librosa.pyin? 具有时变截止频率的低通滤波器,使用Python - Lowpass filter with a time-varying cutoff frequency, with Python 如何用二进制类过滤掉在python中特定频率以下的列? - How to filter out columns with binary classes, that are below a specific frequency in python? 执行 FFT 时提取主频率返回错误频率 - Dominant frequency extraction when doing FFT returns wrong frequency 使用斯坦福 NLP 为 Python 进行信息提取和关系提取 - Information Extraction and Relation Extraction with Stanford NLP for python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM