Filter design and frequency extraction in Python

I am working on a project to find the instantaneous frequency of a multi-component audio signal in Python. I am currently using the Butterworth bandpass filter in conjunction with scipy.signal.lfilter to extract around my desired frequency range. Then I use an analytic signal (from scipy.signal.hilbert ) to get an instant phase that can be deployed to give a frequency.

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

  • I read that in many applications it is recommended to use scipy.signal.filtfilt over scipy.signal.lfilter . Of course, when I apply filtfilt to my data, I get a much smoother instantaneous frequency signal. I would like to know the main differences between them, bearing in mind that I would like to get an output that is as close as possible to the "true" instantaneous frequency.

  • Instantaneous frequency data is non-stationary, which means that in some cases I have to use a wider bandpass filter to capture all my desired data. Apparently, this leads to the appearance of additional noise and random instabilities in my signal. Are there ways to solve these problems, for example, using a more efficient filter?

EDIT

In response to flebool below are some images of the data that I am viewing. Firstly, a comparison of filt and filtfilt : Comparison of <code> filt </code> and <code> filtfilt </code> Both of the above signals had the same Butterworth filter (although the filter function is different), followed by the extraction of the instantaneous frequency (which is shown as a function of time). filtfilt seems to shift and smooth data. Is one of these signals a better approximation of the โ€œtrueโ€ signal?

Note that this graph only shows a subset of a specific signal.

Secondly, the effect of increasing the size of the Butterworth filter: Widening the filter This refers to the same subset of data, as shown in Figure 1. The legend shows the lower and upper bounds of the filter, respectively (the red trace represents the version of the filt data in Figure 1).

Although it may not be clear why I would use a large bandwidth, in some cases the data can be located at different points between, say, 600 and 800 Hz. This is where I would require a wider filter design. You can see that additional noise gets on the trail when the filter expands; I would like to know if there is a way to optimize / improve the filter design.

+6
source share
2 answers

Some rare comments:

1) In the upper image: I cannot comment on what is best between filtering and filter, although the offset in the filterfilt frequency is disturbing. You can get a similar result by applying a low-pass filter to the filter signal.

2) There is no โ€œtrueโ€ instantaneous frequency unless the signal has been detected with a specific tone. However, in my experience of unfolding the Hilbert transform phase, it works well. It is becoming less and less reliable, as the ratio of noise to signal intensity is increasing.

3) Regarding the bottom image, you say that sometimes you need a large band-pass filter. Is it because the signal is very long and the instantaneous frequency varies between 500 and 800 Hz? If so, you can continue processing the window with a length at which the filtered signal has an excellent peak in the Fourier spectrum, extract this peak, set your bandage filter to this peak, apply Hilbert to the window signal, extract the phase, filter the phase.

This is worth doing if you are sure that the signal has other harmonics than the noise and the one that interests you, and it takes time. Before doing this, I would like to make sure that the data I receive is incorrect.

If it is only 1 harmonics + noise, I would again say + hilbert + emergency instant phase + lower limit on the instant phase

+1
source

I canโ€™t speak reasonably to your first problem, but scipy is usually well-documented, so Iโ€™ll start reading some of my material.

An improved filter will certainly help your second problem. You say that the data is "non-stationary", do you know where it will be? Or what frequencies could he take? For example, if the signal is centered around 1 out of 3 frequencies that you know a priori, you can have three different filters and trigger the signal through all 3 (only one gives you the output you want, of course).

If you do not know what signal knowledge is, I will first make a wider BPF, then do some peak detection and apply a more rigorous BPF when you know where the data you want to find is

+1
source

Source: https://habr.com/ru/post/948081/


All Articles