Low pass filter derivation
opened this issue · comments
Could you please possibly explain your code for the low pass filter here
I can see it's a bessel 2nd order but I'm not quite sure I understand the derivation with the denonimator especially why you're multiplying the centre frequency by the sampleTime.
Starting with the general form of a second-order (low-pass) transfer function in the s-domain:
G(s) = k*wc^2 / (s^2 + 2 * d * wc * s + wc^2).
Where k = DC gain, d = damping coefficient, wc = cut-off frequency (rad/s).
Then, we can convert the s-domain transfer function to a differential equation (as 's' is the derivative operator), using y as the output variable, x as the input variable:
y'' + 2 * d * wc * y' + wc^2 * y = wc^2 * x.
Then, using the backward Euler method to discretise the differential equation (Ideally, one should use the Tustin transform, but for simplicity I chose to use the backward Euler method to convert from the continuous domain to the discrete domain.):
y' = (y[n] - y[n-1]) / T and y'' = (y[n] - 2 * y[n-1] + y[n-2]) / T^2.
Substituting and rearranging gives the following difference equation:
y[n] * (1 + 2 * d * wc * T + (wcT)^2) - 2 * y[n-1] * (1 + d * wc * T) + y[n-2] = k * (wcT)^2 * x[n].
This can then be directly implemented in code. Note that for the backward Euler method, a sufficiently small sampling time T (relative to the filter bandwidth) is needed to achieve a good frequency-domain fit between the continuous and discrete versions of the filter.
Let me know if that helps!
Thank you for taking the tiem to explain this , much appreciated.