Skip to main content
added 56 characters in body
Source Link
niaren
  • 2k
  • 16
  • 14

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 |H_1(jw) - H_2(jw)|^2 $$$$ \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 really specify any range for K. But I just want to make it clear to you 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

There is no analytic solution (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 |H_1(jw) - H_2(jw)|^2 $$

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

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

$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

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
added 221 characters in body
Source Link
niaren
  • 2k
  • 16
  • 14

There is no analytic solution (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 |H_1(jw) - H_2(jw)|^2 $$

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

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

$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

There is no analytic solution (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 |H_1(jw) - H_2(jw)|^2 $$

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

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

There is no analytic solution (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 |H_1(jw) - H_2(jw)|^2 $$

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

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

$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
We're not sure that there's no analytic solution. otherwise, please edit and comment saying that it indeed does not exist.
Source Link
Phonon
  • 5.3k
  • 5
  • 38
  • 63

There is no analytic solution (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 |H_1(jw) - H_2(jw)|^2 $$

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

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

There is no analytic solution. 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 |H_1(jw) - H_2(jw)|^2 $$

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

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

There is no analytic solution (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 |H_1(jw) - H_2(jw)|^2 $$

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

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
Change equation to make it displaystyle instead of inline
Source Link
Loading
deleted 103 characters in body
Source Link
niaren
  • 2k
  • 16
  • 14
Loading
deleted 103 characters in body
Source Link
niaren
  • 2k
  • 16
  • 14
Loading
Source Link
niaren
  • 2k
  • 16
  • 14
Loading