My task is simple; I want to simulate analog low-pass filtering of an input signal, using Python. Note that the input signal is an array of values, not an analytical function.
My first question is if it simply is possible? If so, where is the line drawn between making a digital (FIR/IIR) filter and simulating an analog filter?
My second question is how I, in python, can make two equivalent simulations, using convolution in one, and converting the input signal to frequency domain in the other. Convolution is used in the link below, and it would help me a lot to see how exactly the same thing would be done by instead using fft (even though I think it's using an FIR filter, not simulating an analog filter).
http://glowingpython.blogspot.nl/2012/02/convolution-with-numpy.html
Thanks a lot in advance!
Answer
What's not clear to me is what the fundamental difference (if any) is between simulating an analog filter and making a digital filter.
Either way, these functions will produce "ba" transfer function outputs, but the b and a are totally different.
For a 2nd-order filter, for instance, b = [b0, b1, b2] and a = [a0, a1, a2]. These are the coefficients of the transfer function.
For an analog filter, this represents a transfer function like this:
$$H(s) = \frac{b_2 s^2 + b_1 s + b_0}{a_2 s^2 + a_1 s + a_0}$$
For a digital filter, the transfer function is:
$$H(z)=\frac{b_0+b_1z^{-1}+b_2z^{-2}} {a_0+a_1z^{-1}+a_2z^{-2} }$$
Note that the input signal is an array of values
Then you are doing digital filtering. You can simulate analog filtering this way, but it's only going to be a simulation.
All the Python IIR filter functions you're talking about, when outputting a digital filter, design it as an approximation of the analog filter using an analog filter transfer function prototype and then converting it to digital using the bilinear transform and frequency warping. Yes, they can output analog transfer functions, but I think that's only useful for building actually analog electronic filters, or for plotting the frequency response, impulse response, etc.
The Bessel in particular is a bad approximation as you get near fs/4, because the important property of a Bessel filter is group delay, not amplitude, and phase/group delay is not preserved by the bilinear transform (red vertical line is fs/4):
More plots of digital Bessel filter
You can make the simulation closer to what an analog filter would produce by putting a large margin between the highest frequency in your signal and the sampling frequency, called oversampling. Assuming your "array of values" is correctly bandlimited, then you can upsample them and then apply the digital filter using lfilter and the ba digital filter coefficients you found earlier. If not, you need to bandlimit the analog signal and then sample it at a significantly higher rate. How did you get your sampled signal? If you are generating it digitally, it is probably not bandlimited, unless you specifically thought of bandlimiting while generating it.
for example a 1st-order Bessel filter
All 1st-order filters are the same, the "1st-order Bessel" is the same thing as a "1st-order Butterworth" or anything else.
No comments:
Post a Comment