I know there's a thread similar to this one here, but the OP is asking the reverse of what I'm trying to find here. I've done some research on the web with very few sources coming up with actual solutions to this problem. What techniques are used to give an approximation of an FIR filter given one or more IIR filters with say the same order?
-
seems to me that the other thread is about the same thing as your question. i always thought that the Prony method was the conventional way to address it. – robert bristow-johnson Nov 26 '16 at 00:25
-
Given an IIR filter, you want to find the FIR yes? because that would be the inverse of the link you provided... – msm Nov 26 '16 at 00:26
-
1That seems to be an odd question: an FIR filter is just a special case of an IIR filter just with $a_1$, $a_2$ ... all being zero. Nothing needs to be approximated unless you want some other constraints, i.e. the order of the IIR being a lot lower than that of the FIR. – Hilmar Nov 26 '16 at 00:40
-
1@Hilmar I really don't think by putting $a_1,a_2,\cdots$ equal to zero, an approximate of the original IIR filter can be achieved. It will become FIR, but not an approximate for the original IIR. As I explained in the answer, I think the correct way is to truncate the time-domain impulse response, not the system function. – msm Nov 26 '16 at 01:46
-
i think the OP should be clear. even the tread title is self-contradictory. also the IIR $\to$ FIR thing really is just about windowing and truncating the IIR impulse response. i'm gonna make the title self-consistent, and if the OP objects he/she can change it to a consistent meaning. – robert bristow-johnson Nov 26 '16 at 02:09
-
@robert bristow-johnson I was confused by the arrow too. But then I thought it could be interpreted as a limit: find IIRs such that "approach" a FIR. For whatever that means – Laurent Duval Nov 26 '16 at 08:26
-
@robertbristow-johnson The problem with saying FIR --> IIR is that it implies (at least to me) that we are starting with an FIR filter and using it to approximate an IIR filter. I want to do the exact opposite of that, which is, given an IIR filter, I want to approximate an FIR filter. This was the reason why I had IIR --> FIR because this means we are going "from" IIR "to" FIR. Correct me if I'm wrong. – ragzputin Nov 27 '16 at 00:10
-
@ragzputin It means converting an arbitrary discrete-time LTI system, which can be complete described, from an input/output POV, with $h[n]$, however it is defined. and what you want to get out of the process is a description for an IIR filter $$ H(z) = \frac{\sum b_i z^{-i}}{1+\sum a_i z^{-i}} $$. – robert bristow-johnson Nov 27 '16 at 00:38
-
@ragzputin you can find what you are looking for by reading my answer! feel free to ask if you have questions... – msm Nov 27 '16 at 08:07
-
Answer upvotes and better answer validation are required for this question – Laurent Duval Jul 28 '19 at 14:45
3 Answers
Approximating the frequency response of an IIR filter or physical process using an FIR filter is useful in learning control. It is quite common to do FIR filter design based on frequency response specifications. You probably want to check out two standard papers on the subject:
[1] J. H. McClellan, T. W. Parks, and L. R. Rabiner, “A computer program for designing optimum FIR linear phase digital filters,” IEEE Trans. Audio Electroacoust., vol. 21, no. 6, pp. 506–526, 1973.
[2] L. R. Rabiner, “Techniques for Designing Finite-Duration Impulse-Response Digital Filters,” IEEE Trans. Commun. Technol., vol. 19, no. 2, pp. 188–195, Apr. 1971.
Broadly, you either do windowed direct sampling of your desired frequency response, or you use one of several optimization methods to achieve similar results. If you disregard the linear phase delay in an FIR, you can practically make the IIR and FIR responses identical, if the FIR filter order is high enough.
As an elaboration on one of the other answers given; if you have an IIR filter $G(z^{-1})$, then you can do FIR filter design by frequency sampling by taking $M$ samples of the frequency response of $G(z^{-1})$, denoted $\widehat{G}(k)$, and then taking the inverse discrete Fourier transform (IDFT) of $\widehat{G}(k)$. The unit impulse response $g(n)$ of $\widehat{G}(k)$ is \begin{align*} g(n) = \frac{1}{M} \sum\limits_{k=0}^{M-1} \widehat{G}(k) \text{e}^{j \frac{2 \pi k n}{M}} \; , \end{align*} where $n \in [0, M-1] \cap \mathbb{N}_{0}$. The FIR filter is then expressed in the $z$-domain as \begin{multline*} F(z^{-1}) = g(0) + g(1) z^{-1} + ... + g(M-1) z^{-M+1} = \sum_{n=0}^{M-1} g(n) z^{-n} \; . \end{multline*}
The frequency-sampling method results in a unit impulse response which has been convoluted with a rectangular window of the same length in the frequency domain. The frequency response of $F(z^{-1})$ is therefore affected by the large side-lobes of the rectangular window. As a result, the approximation error of $F(z^{-1})$ is large between the frequency samples. This can be alleviated by the use of a window that do not contain abrupt discontinuities in the time domain, and thus have small side-lobes in the frequency domain, i.e., the window smooths the frequency response of $F(z^{-1})$.
A windowed FIR filter $\tilde{h}(n)$ is created from an un-windowed FIR filter $h(n)$ as \begin{align*} \tilde{h}(n) = w(n) h(n) \end{align*} where $w(n)$ is a window function which is non-zero only for $n \in [0, M-1] \cap \mathbb{N}_{0}$. The frequency-domain representation of the window function $W(k)$ is found as \begin{multline*} W(k) = \sum\limits_{n=0}^{M-1} w(n-M/2) \textrm{e}^{-j \frac{2 \pi k n}{M}} = \left[ \sum\limits_{n=0}^{M-1} w(n) \textrm{e}^{-j \frac{2 \pi k n}{M}} \right] \textrm{e}^{-j \frac{2 \pi k}{M} \frac{M}{2} } \; , \end{multline*} where the term $\textrm{e}^{-j (2 \pi k / M) (M/2) }$ comes from the fact that the rectangular window is not centered around $n=0$, but is time-shifted to be centered around $n=M/2$. This phase term will cause distortion of $h(n)$, unless $h(n)$ is also phase-shifted to compensate. The unit impulse response $g(n)$ is therefore phase-shifted before windowing. Due to the circular shift property of the DFT, this can be done by rearranging $g(n)$ such that \begin{equation*} \bar{g}\left( n \right) = \begin{cases} g\left( n + M/2 \right) , & \hspace{-0.6em} n = 0,1, ..., \frac{M}{2} - 1 \\ g\left( n - M/2 \right) , & \hspace{-0.6em} n = \frac{M}{2},\frac{M}{2}+1, ..., M-1 \end{cases} \end{equation*} for the case when $M$ is even. The response is then represented by the FIR filter \begin{equation*} \bar{F}(z^{-1}) = \sum_{n=0}^{M-1} \bar{g}(n) z^{-n} = z^{-M/2} F(z^{-1}) \end{equation*} which is $F(z^{-1})$ delayed by $M/2$ steps. Applying the window $w(n)$ to the time-shifted impulse response $\bar{g}(n)$, \begin{equation*} \tilde{g}(n) = w(n) \bar{g}(n) \; , \end{equation*} the filter \begin{equation*} \tilde{F}(z^{-1}) = W(z^{-1})*\left[ z^{-M/2} F(z^{-1}) \right] \end{equation*} is obtained. Now, $G^{-1}(z^{-1}) \left[ W(z^{-1})*F(z^{-1}) \right] \approx 1$ if the FIR filter is accurate. Note that the phase due to $z^{-M/2}$ is taken out.
- 1,035
- 6
- 12
-
I read [2] and was wondering - isn't frequency sampling just a type of windowing method? Why does L. R. Rabiner write it as a complete method on its own? As you said yourself, frequency sampling is simply done using a rectangular window, which makes it a type of windowing method, right? – ragzputin Nov 29 '16 at 00:33
-
@ragzputin: Good question, I'm a little rusty on the theory, but I believe what is meant by the windowing method is to expand the periodic (since it is discrete time) desired frequency response as a Fourier series, using the resulting coefficients as the impulse response, and then windowing the truncated series coefficients (to reduce ripples due to Gibbs phenomenon). This compared to the direct sampling of the frequency response (and optional windowing to reduce ripples)... – Arnfinn Nov 29 '16 at 01:09
-
@ragzputin: If you have MATLAB or clones, these methods are implemented as
fir1andfir2. One caveat with these implementations is that they assume you want linear phase, so they are not all that useful for IIR filter approximation. – Arnfinn Nov 29 '16 at 01:13 -
Your first comment didn't say anything about direct frequency sampling. Could you elaborate on frequency sampling? – ragzputin Nov 29 '16 at 01:46
-
@ragzputin: So, for the windowing method, you choose the FIR coefficients by directly computing a truncated set of the Fourier series coefficients of your desired frequency response (i.e. for a brick wall filter using the formula in https://en.wikipedia.org/wiki/Pulse_wave). This method is therefore restricted to cases where it is possible to find the Fourier series coefficient (so it wont work for an arbitrary frequency response, like an arbitrary IIR filter response, at least not easily). – Arnfinn Nov 29 '16 at 03:03
-
@ragzputin: For frequency sampling, you sample the frequency response (take values at equidistant points), and compute the inverse discrete Fourier transform for those samples... This means you can use any desired frequency response, and you don't have to worry about finding the Fourier series coefficients for it. Hence you can take any IIR filter response as a prototype and easily find an FIR approximation to it... – Arnfinn Nov 29 '16 at 03:04
-
@ragzputin: You use windowing in either case is to reduce ripple effects. Maybe a bit confusing to call it the windowing method, when it is also common to use windowing in the frequency sampling method... – Arnfinn Nov 29 '16 at 03:08
-
so you can only do windowing on periodic signals? that's quite a huge limitation right? – ragzputin Nov 29 '16 at 04:20
-
@ragzputin: Not quite: you can really only do windowing for a desired frequency response that can easily be described by a Fourier series. Recall that the frequency response for a discrete-time system is periodic, that is why you can express the frequency response (not the time response) as a Fourier series. Due to the way the Fourier series is defined, you can use the series coefficients as the impulse response coefficients. So if you have a brick wall filter, you can express this by the Fourier series of a pulse wave. The coefficients are the impulse response. – Arnfinn Nov 29 '16 at 04:49
-
@ragzputin: The point of using the windowing method is that it is really easy to get the impulse response for a brick wall filter, since the expression for it is so simple... $g(n) = 2/(n \pi) \sin( \pi n \omega_c )$ for $n < 1$ and $n > 1$, $g(0) = 2 \omega_c$. Just take as many as you need to get a good approximation, window it, and you are done. It is very cheap. If you don't have the expression for the coefficients you can't use it. These can be found for IIR filters as well, but you have to solve for the time-response, and it will not usually be worth it in terms of computational effort. – Arnfinn Nov 29 '16 at 04:57
-
@ragzputin: For frequency sampling you have complete freedom to choose whatever frequency response you want (excluding the phase delay). This means you can compute the frequency response of any linear filter and approximate it. You can even measure the response of e.g. a robot arm or a microphone, and approximate the response without knowing what the IIR filter describing the dynamics is... – Arnfinn Nov 29 '16 at 05:05
-
@ragzputin: If you are wondering about differences in FIR filter design methods, you might want to open another question... – Arnfinn Nov 29 '16 at 05:21
The easiest approach is to consider the impulse response of the IIR which is infinite and truncate it somewhere (depending on what order you consider for the approximate FIR filter).
For example, consider the IIR filter with the impulse response $h[n]=a^nu[n]$, where $a$ is positive and $|a|<1$. We can represent it as $$h[n]=\sum_{k=0}^{\infty} a^k\delta[n-k]$$
So the impulse response of the $N$'th order approximation FIR filter would be $$h_{\text{FIR}}[n]=\sum_{k=0}^{N} a^k\delta[n-k]$$
Larger $N$ you consider, closer the FIR will be to the original IIR.
This is an easy approach to simulate the IIR filter's behavior in general. You should be more specific about what aspect of the IIR filter you want to simulate (e.g, pass-band behavior, pass-stop transition, etc.) to get a more specialized answer.
In the example below the IIR filter $$H(z)=\frac{1}{1-0.9z^{-1}}$$ is approximated by three FIR filters of orders $N=10,15,25$ where $$H_{\text{FIR}}(z)=\sum_{k=0}^{N} 0.9^kz^{-k}$$
b1 = 1;
a1 = [1 -0.9]; % IIR filter with impulse response (0.9)^n*u[n]
[H,w] = freqz(b1,a1); % Plot the frequency response
plot(w/pi,10*log10(H),'b','Linewidth',2);
hold on; % Plot setup
text = 'IIR Filter ';
color = ['k','g','r'];
N = [10 15 25]; % Three different FIR filter orders
for i=1:3 % Truncate the impulse response
b2 = [];
for n=0:N(i)
b2 = [b2 0.9^n];
end
[H,w] = freqz(b2,1); % frequency response of FIR filter of order N
plot(w/pi,10*log10(H),color(i));
text(i+1,:)=['FIR order = ' num2str(N(i))];
end
grid on
legend(text)
xlabel('Normalized Frequency')
ylabel('Magnitude (dB)')
- 20,661
- 4
- 38
- 76
- 4,285
- 1
- 13
- 25
-
1msm, what you are discussing is, essentially, the windowing method of FIR design using the rectangular window. – robert bristow-johnson Nov 26 '16 at 02:15
-
so, i am sorta asking the same question a different way: *what is the difference between
h()andb2()? – robert bristow-johnson Nov 27 '16 at 08:16 -
@robertbristow-johnson As I also explained in the answer,
b2is the truncated version of the impulse response of the IIR filter with system function(b1,a1). BTW thanks for the edit. – msm Nov 27 '16 at 08:25 -
it also appears to be the direction (IIR $\to$ FIR) that the OP wants to go. i had it wrong, because i thought the problem is a little trivial and uncommon (if your IIR does what you want, why convert to a higher-order FIR?). one aspect that is not trivial is that might want to window your IIR with a window other than rectangular. perhaps a Hamming (for something simple) or a Kaiser (for something good) and put the 0th sample of $h[n]$ in the center of the window. so you'ld be only applying the right-hand half of the window and the left-hand half of the window multiplies $h[n]=0$ anyway. – robert bristow-johnson Nov 27 '16 at 08:30
-
Indeed, it seems that by applying a form of weighting the FIR impulse response (i.e. windowing), one could achieve a better approximate with a lower filter order. Somehow, compensating the impact of truncation... This can be formulated as an optimization problem. – msm Nov 27 '16 at 08:35
-
this is a well-established, old problem. it is the optimized design of an FIR from a more precise spec. you can do it either the Parks-McClellan (
firpm()or alternativelyfirls()) way or the windowing way (usually withkaiser()) depends on how well you want to match the frequency response (as opposed to the impulse response). – robert bristow-johnson Nov 27 '16 at 08:40 -
There are other options such as frequency sampling (
arbmag) as well. But still, "the easiest" solution is truncation. – msm Nov 27 '16 at 09:49 -
uhm, "frequency sampling" is what we do for either an P-McC or Least Squares or windowing technique. it's what you do with it after sampling the frequency response you want. – robert bristow-johnson Nov 27 '16 at 15:02
-
@msm what happens to the phase of the closely approximated FIR filters? They still remain linear? – ragzputin Nov 28 '16 at 19:50
-
@msm If I use a better window function (e.g. Hamming, Blackman, Kaiser etc), will I get faster convergence using fewer samples? – ragzputin Nov 29 '16 at 00:23
-
@ragzputin Linear phase is only achieved when the impulse response is symmetric (i.e. $h[n]=h[N-1-n]$) which is not necessarily the case always. and No not just changing the window function will improve the approximation necessarily. You should solve an optimization problem as well (least squares or something else) which is not related to windowing etc. – msm Dec 01 '16 at 09:11
[EDIT: beyond my initial belief that "nobody does that", the OP made me think of situations where this could be useful. Let's start with the obvious]
Given the FIR with $z$-transform: $$\sum_{i=0}^P b_iz^{-i},$$ you can get a very close IIR approximation with:
$$\frac{\sum_{i=0}^P b_iz^{-i}}{1+\sum_{j=1}^Q a_iz^{-i}}$$ with $Q\le P$, and the $a_i$ of very small absolute value, as long as you want to keep "say the same order". An example is given below. I still wonder about the practical interest of such a design.
Perhaps to introduce some instability in an FIR, that is too good in that respect :)
data = randn(1024,1);
fFIRNum = [1 2 1];
fFIRDen = [1];
fIIRDen = [1 0 1e-6];
subplot(3,1,1)
plot([data])
legend('Data')
axis tight;grid on
subplot(3,1,2)
plot([filter(f1,f2,data),filter(f1,f3,data)])
legend('FIR','IIR')
axis tight;grid on
subplot(3,1,3)
plot([filter(f1,f2,data)-filter(f1,f3,data)])
legend('FIR/IIR difference')
axis tight;grid on
The obvious put aside, let me imagine a context where an IIR approximation could be useful. Suppose you want to perform a moving average filtering. If you want to make it adaptive, you have to change the length of the window, and a sudden change in the number of averaged samples could affect the smoothed signal abruptly. At minimum, you can only change the window length by $\pm 1$ unit length. The Exponentially Weighted Moving Average (EWMA) $$y(n) = ax(n) + (1 – a)y(n–1)\,.$$ is an IIR. It may mimic FIR rectangular windows of different lengths, depending of the forgetting factor $a$. The Exponentially Weighted Moving Average has been discussed here recently.
One could perform an adaptive EWMA by smoothly varying $a$ in a more continuous way that hoping the window length from sample to sample. One instance can be found in An Adaptive Exponentially Weighted Moving Average Control Chart, 2003.
- 31,850
- 3
- 33
- 101
-
of course you can get a very close IIR approximation to $$\sum_{i=0}^P b_iz^{-i},$$ with:
$$\frac{\sum_{i=0}^P b_iz^{-i}}{1+\sum_{j=1}^Q a_iz^{-i}}$$ by setting all $a_i=0$. i don't see what the point is.
– robert bristow-johnson Nov 26 '16 at 02:21 -
1@robert bristow-johnson That was exactly the point of my answer. However, if you set $a_i=0$, I am not sure the filter qualifies for IIR – Laurent Duval Nov 26 '16 at 08:23
-
i think you're right, so that's why i think he meant to ask, how to derive an IIR that matches a given $h[n]$ to with some degree of approximation. – robert bristow-johnson Nov 26 '16 at 18:43


