Thursday 17 December 2015

What Is the Best First Order IIR (AR Filter) Approximation to a Moving Average Filter (FIR Filter)?



Assume the following first order IIR Filter:


$$ y[n] = \alpha x[n] + (1 - \alpha) y[n - 1] $$


How can I choose the parameter $ \alpha $ s.t. the IIR approximates as good as possible the FIR which is the arithmetic mean of the last $ k $ samples:


$$ z[n] = \frac{1}{k}x[n] + \frac{1}{k}x[n-1] + \ldots + \frac{1}{k}x[n-k+1] $$


Where $ n \in [k, \infty) $, meaning the input for the IIR might be longer than $ k $ and yet I'd like to have the best approximation of the mean of last $ k $ inputs.


I know the IIR has infinite impulse response, hence I'm looking for the best approximation. I'd be happy for analytic solution whether it is for $ {L}_{2} $ or $ {L}_{1} $ cost function.


How could this optimization problems can be solved given only 1st order IIR.


Thanks.



Answer



There is no analytic solution for $\alpha$ being a scalar (I think). Here is a script that gives you $\alpha$ for a given $K$. If you need it online you can build a LUT. The script finds the solution that minimizes



$$ \int_{0}^{\pi} dw \quad \left|H_1(jw) - H_2(jw)\right|^2 $$


where $H_1$ is the FIR frequency response and $H_2$ is the IIR frequency response.


You did not specify any range for K. But I just want to make it clear that the following system is equivalent to your mean filter and has the same computational complexity and your first order IIR!


$H(z) = \frac{1}{K} \frac{1 - z^{-K}}{1-z^{-1}}$


function a = find_a(K)

w = 0.0001:0.001:pi;
as = [-1:0.001:-0.001 0.001:0.001:1];

E = zeros(size(as));

for idx=1:length(as)
fJ = J(w,as(idx),K);
E(idx) = sum(fJ);
end

[Emin, indx] = min(E)
a = as(indx)

function f = J(w,a,K)
num = 2*(2-a)*(1-cos(w*K)) + 2*(cos(w*(K-1)) - cos(w)) - 2*(1-a)*(cos(w)-cos(w*(K+1)));

den = (2-a)^2 + 1 + (1-a)^2 + 2*(1-a)*cos(2*w) - 2*(2-a)^2*cos(w);
f = -(a/K)*num./den;
f = f+(1/K^2)*(1-cos(w*K))./(1-cos(w))+a^2./(1+(1-a)^2-2*(1-a)*cos(w));
end

end

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 「ない...