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.
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[n−1],0<α<1
Its transfer function is
H(z)=α1−(1−α)z−1
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=1−cos(ω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
α≈1−e−ω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=nT≈y(nT)−y((n−1)T)T
This is equivalent to replacing s by (1−z−1)/T in the continuous-time transfer function
H(s)=11+sτ
which results in
H(z)=11+(1−z−1)τ/T=11+τ/T1−τ/T1+τ/Tz−1
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.
No comments:
Post a Comment