Wednesday, 24 February 2016

Single-pole IIR low-pass filter - which is the correct formula for the decay coefficient?


A single-pole IIR low-pass filter can be defined in discrete time as y += a * (x - y), where y is the output sample, x is the input sample and a is the decay coefficient.


However, the definition of a varies. On Wikipedia, it's defined as 2πfc/(2πfc+1) (where fc is the cutoff frequency).


But here, a is defined as follows: 1 - e^-2πfc.


Their graphs look similar, but which one is more accurate?


The blue graph is the Wikipedia formula, the green is the second one, fc is the x-axis. GeoGebra graph



Answer



The given single-pole IIR filter is also called exponentially weighted moving average (EWMA) filter, and it is defined by the following difference equation:


y[n]=αx[n]+(1α)y[n1],0<α<1



Its transfer function is


H(z)=α1(1α)z1


The exact formula for the required value of α that results in a desired 3dB cut-off frequency ωc was derived in this answer:


α=y+y2+2y,y=1cos(ωc)


Even though it should be easy enough to compute α from (3), there are several approximative formulas floating around the internet. One of them is


α1eωc


In this answer I've explained how this formula is derived (namely, via the impulse invariant transformation of the corresponding continuous-time low pass filter). This answer compares the approximation (4) with the exact formula, and it is shown that (4) is only useful for relatively small cut-off frequencies (of course, small compared to the sampling frequency).


In the wikipedia link given in the question, there is yet another approximative formula:


αωc1+ωc


[Note that in all formulas of this answer ωc is normalized by the sampling frequency.] This approximation is also derived from discretizing the corresponding analog transfer function, this time not via the impulse invariant method, but by replacing the derivative by a backward difference:



dy(t)dt|t=nTy(nT)y((n1)T)T


This is equivalent to replacing s by (1z1)/T in the continuous-time transfer function


H(s)=11+sτ


which results in


H(z)=11+(1z1)τ/T=11+τ/T1τ/T1+τ/Tz1


Comparing (8) to (2) we see that


α=11+τ/T


Since the (continuous-time) 3dB cut-off frequency is Ωc=1/τ, we obtain from (9)


α=ΩcT1+ΩcT


Equating the discrete-time cut-off frequency ωc with ΩcT in (10) gives the approximation (5).



The figure below shows the actually achieved cut-off frequency for a given desired cut-off frequency for the two approximations (4) and (5). Clearly, both approximations become useless for larger cut-off frequencies, and I would suggest that approximation (5) is generally useless.


enter image description here


No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...