IIR vs FIR

Discussion in 'Software' started by Gyro Gearloose, Aug 22, 2019.

  1. Gyro Gearloose

    Gyro Gearloose Audiosexual

    Joined:
    Jul 8, 2019
    Messages:
    4,237
    Likes Received:
    1,846
    Location:
    Germany
    Iowa Hills Software Digital and Analog Filters
    Differences Between FIR Filters and IIR Filters Home

    If you found this web page because you Googled "the difference between FIR and IIR", then it is likely you have already seen numerous other web pages on this subject and you are still trying to get a clear answer to your question. So lets start by with a clear advantage that FIR has over IIR.

    Because of the way FIR filters can be synthesized, virtually any filter response you can imagine can be implemented in an FIR structure as long as tap count isn't an issue. For example, Butterworth and Chebyshev filters can be implemented in FIR, but you may need a large number of taps to get the desired response. So we generally use prototypes other than the s domain polynomials as prototypes for FIR filters. As another example, if you want a band pass filter with two pass bands, or a band pass filter with specific phase properties, an FIR can do the job with no problem.

    IIR filters on the other hand are essentially restricted to the well defined responses that can be achieved from the s domain polynomials such as the Butterworth. It is quite difficult to synthesize a user defined filter in an IIR structure.

    It is quite possible however that the most important difference between an IIR and FIR isn't the filter itself, but rather how the filter is implemented. The beauty of FIR filters, and quite possibly their most important feature, is that they can be implemented with integer math. As you are surely aware, everyone wants small, low power, low cost, portable devices. These devices typically use a processor similar to the Texas Instruments MSP430, or an FPGA, or an ASIC.

    These types of processors work great and are as common as dirt, but seldom have a floating point math core. Integer math is the standard because its easy, cheap, fast, and low power. (Floating point math is then done in code, which is very slow.) So the only reasonable way to implement a digital filter in one of these devices is to use FIR. Thus it is the hardware, not the characteristics of the filter that determines whether FIR or IIR will be used.

    IIR filters can't be implemented in integer math because the IIR coefficients can't be scaled to integer values without having the filter's math calculations explode (the problem is with the feedback coefficients). For example, scaling the coefficients by 16, which won't create nearly enough significant digits for filtering, will cause the calculations to go exponential. Try it.

    The rest of this page shows some of the basic differences between an FIR and IIR filters. In the first plot below, we compare the frequency responses of a12 pole Butterworth IIR and a typical FIR filter (with emphasis on the word typical). The reader should understand that if we want to, we can implement the 12 pole Butterworth as an FIR and obtain an identical response, but that isn't typically done simply because of the excessive number of taps required to achieve the Butterworth response in an FIR.

    These two filters have comparable magnitude responses. Notice the differences in the knee of the pass band at Omega = 0.2. In general, an IIR filter will have a sharper knee than a comparable FIR filter. Also, the slope of IIR filter's transition band will be 6 dB / octave / pole. A typical FIR transition band slope changes with frequency as shown here (again, emphasis on the word typical).

    This FIR requires 50 multiplies + 50 adds while the IIR requires 30 multiplies + 36 adds for its 6 second order sections. The FIR has a constant group delay of 24.5 (equal to (NumTaps-1)/2 ) while the IIR has a much lower, but non-constant group delay.

    [​IMG]



    Step Response and Delay

    The group delay and impulse response are the most basic differences between an FIR and IIR filter. An IIR filter has, at least in principle, an infinitely long impulse response while an FIR filter's impulse response is as long as its tap count. If an infinitely long impulse response sounds problematic, remember that all analog filters have the same type of response.

    Closely related to the impulse response is the filter's step response. This next plot shows the step response for the two filters above. It shows the amount of time for a pulse to propagate through the filter (time is in samples). Note that the pulse is delayed more in the FIR than the IIR. This is fairly typical. Compare these delay times with the group delay values plotted above.

    [​IMG]

    The amount of overshoot and ringing is an important difference between these two step responses. However, this difference has nothing to do with whether the filter is an IIR or FIR. The IIR filter shown here is a 12 pole Butterworth. A 12 pole Butterworth implemented as an FIR would have an identical step response.

    Having said this, it is important to remember that the amount of overshoot in the step response is a function of the filter's group delay characteristics, and the slope of the filter's transition band. We chose to show typical FIR and IIR filters here. FIR filters typically have a constant group delay, which will reduce the amount of ringing and overshoot in the step response. However, we could have shown an IIR Bessel filter, which would have almost no overshoot or ringing.

    Just to be clear, if the magnitude responses are similar, then an FIR will typically have less overshoot and ringing because it typically has better group delay characteristics than the IIR.

    Impulse Response

    Here are the impulse responses for the two filters above (this time scale is different than the step response plot above). Again, the FIR could have had the same impulse response as the IIR, but we are showing a typical FIR filter. The typical FIR filter's impulse response is centered at (N-1)/2 and is symmetric about the center. The typical IIR impulse response starts sooner, and ends later. Again, the difference in ringing has nothing to do with IIR or FIR, but rather the prototype used to synthesize the filter.

    It may be of interest to the reader that the impulse response of a12 pole Butterworth filter implemented in an opamp circuit would have the same characteristics as this IIR digital filter.

    [​IMG]

    Stability

    An important difference between IIR and FIR filters is the potential for the IIR filter to be unstable. An FIR filter will be stable no matter how it is synthesized or implemented (it has no feedback). On the other hand, an IIR filter with improperly placed poles can't be made stable no matter how it is implemented. Please remember however that OpAmp filters are the same as IIR filters in this respect. Both IIR and OpAmp filters need to be carefully synthesized and implemented or they risk being unstable.

    So, how difficult is it to get a stable IIR filter designed and implemented? The following link discusses the stability of the IIR filters synthesized by our free IIR filter program. It discusses IIR filter pole locations, compares the frequency response of IIR filters to known stable filters, and shows a method by which the engineer can assess the margin of stability the IIR filter has. IIR Filter Stability

    Math Register Size

    For the sake of comparing an FIR to an IIR, we will assume we are using a fixed point processor. Both the number of bits to left and to the right of the decimal place are important. The number of bits to the right determine the maximum attenuation one is able to achieve with the filter. The number of bits to the left determine the register's maximum value (overflow must never occur).

    An important difference between FIR and IIR filters is the peak math values generated by the filter as a signal is processed. Because of the overshoot in the filters step response, square waves typically create the largest math values in a filter.

    For the two filters shown on this page, the peak math register value for the FIR is only 1.3, and this is fairly typical of an FIR filter. In fact, FIR filters never generate math values greater than 2 (for a signal with ±1 amplitude and unity filter gain).

    IIR filters are quite different in this respect. The IIR filter shown above has a peak math value of 6.5 while filtering a square wave, but there is no such thing as a typical peak math value for IIR filters. They can range from 1.0 to 10,000 or even higher. The filter's peak math value is a strong function of the polynomial it is based on and its selectivity. The more selective the filter, the higher the math values. If working with relatively low distortion filters (moderate selectivity), you can expect the peak math value to be less than 32, but even this small value would require 4 more bits than an FIR filter.

    Implementation Structures

    An important difference between IIR and FIR filters is in the implementation structure. FIR filters are usually implemented as Nth order polynomials. IIR filters on the other hand, can be implemented this way, but only if a floating point processor is available. If using a fixed point processor, an IIR filter must be implemented as a series of second order sections (biquads).

    The reason for this lies with the magnitude of the math values generated by the filter, which we show in the following table. If using fixed point, the larger math values require more register bits to prevent overflow, which is strictly forbidden. Here we give the peak math values for an IIR filter implemented both ways. For example, if implemented in 2nd order sections, the Butterworth filter needs 3 integer bits to prevent overflow, but would require 18 integer bits if implemented as an Nth order poly. The number of fractional bits required would be the same in both cases. (Integer bits are needed to accommodate math values greater than 1, while the fractional bits are needed to achieve the desired stop band performance. These are completely separate problems.)

    12 Pole Filter Types 2nd Order Peak Math Nth Order Peak Math
    Butterworth Low Pass 6.5 (3 bits) 194,806 (18 bits)
    Cheby Low Pass 0.2 dB Ripple 94.3 (7 bits) 120,684,358 (27 bits)
    Butterworth Band Pass 13.9 (4 bits) 6.134E14 (50 bits)
    Cheby Band Pass 0.2 dB Ripple 44.9 (6 bits) 1.982E29 (98 bits)

    [​IMG]

    It should be obvious that except for the denominator, IIR and FIR structures are identical.

    To summarize, an FIR filter is almost always implemented as an Nth order poly. It can be implemented in 2nd order sections, but there is no need to and finding the polynomial's N roots is numerically difficult because of their close proximity to one another.

    An IIR filter can be implemented either way if using floating point. If using fixed point however, an IIR filter must be implemented in 2nd order sections because of practical hardware considerations.

    The Example FIR IIR C Code page gives code examples for implementing both FIR and IIR filters.



    IIR Zero Input Limit Cycles

    IIR filters differ from FIR filters in that some IIR filters can suffer from a phenomenon known as Zero Input Limit Cycles. This is a problem related to register size where the IIR filter is unable to clear its registers and its output can't settle at zero after the input goes to zero. The filter's output may oscillate indefinitely because a small residual signal continues to circulate within the filter.

    Of course, an ideal IIR filter's output will never settle at zero in theory, but this is only true if the registers have infinite precision. The truncation caused by limited register size will limit the length of the filters impulse response and should also prevent limit cycles. Notch and high pass IIR filters are most susceptible to this problem and will require extra register bits to prevent this phenomenon from occurring.



    Pole Zero Locations

    If you are somewhat new to filter design, you may be wondering how the filter's pole zero locations affect the filter's response.

    Here we show the pole zero locations for a 5 pole Inverse Chebyshev low pass implemented in both IIR and FIR. Note the pole zero locations with respect to the filter's corner frequency. Also note how the 5 IIR zero locations are maintained in the FIR implementation.

    As shown on the left, the FIR response is slightly different than the IIR response, but this difference diminishes to zero as the tap count is increased. The slight difference in the 5 zero locations on the unit circle also diminishes to zero as the tap count is increased.

    [​IMG]

    Here is a more typical zero plot for an FIR filter. All of its stop band zeros are on the unit circle. Again, note the 14 zeros on the unit circle and the 14 nulls in the response.

    Since this is a linear phase filter, the pass band zeros come in sets of 2 and 4. A zero on the real axis has a counterpart on the axis reflected about the unit circle. If not on the real axis, the zeros come in a set of four, reflected about the axis and reflected about the unit circle. It should be noted that this filter has a zero at the origin that isn't shown.

    [​IMG]



    Apples and Oranges ?????

    In general, trying to compare an IIR filter to an FIR filter is a bit like comparing apples to oranges. However, since we can implement an analog filter as an FIR, lets try to make a comparison using a data filter example.

    Here we implement a 12 pole Adjustable Gauss filter with gamma = 0, which has a response midway between a Gauss and Butterworth. The responses for both the IIR and FIR are shown here.

    As can be seen, there is little difference in the performance of these two filters. The FIR requires 36 Multiply/Adds while the IIR requires 30 Multiply/Adds plus 6 adds, so the difference here is also negligible, except that the FIR can be done using integer math. So, for this particular filter, there is very little difference between an FIR and IIR filter.

    [​IMG]

    [​IMG]

    The point of this example was to make it clear that in terms of performance, the difference between an FIR and IIR can be minimal. This is especially true when a polynomial such as the Bessel, Gauss, or Inverse Chebyshev is used as the FIR prototype. For more discussion on this, see Polynomial FIR Filters.

    To summarize, an IIR filter is neither better or worse than an FIR filter. Each has its place and the project's overall requirements will determine which is the better solution.

    This web site is intended for engineers who are not experts in filter design, but still need to implement a good filter, whether it be analog or digital. The programs here are free, and I give examples of implementation code for the digital filters, and implementation tips for the analog filters. Ultimately however, you have to dig in and work with this stuff to learn it.
    --------------------------------------------------------------
    -------------------
    ------
    just first 1:30

    -----
    -------------------
    ---------------------------------------------------------------

    total overkill ...
    https://home.zhaw.ch/~dqtm/dsv1/vorlesung/dsv1kap5_filter_folien_IIR.pdf
     
    Last edited: Aug 22, 2019
  2.  
  3. Gyro Gearloose

    Gyro Gearloose Audiosexual

    Joined:
    Jul 8, 2019
    Messages:
    4,237
    Likes Received:
    1,846
    Location:
    Germany
    • Like Like x 2
    • Funny Funny x 1
    • Interesting Interesting x 1
    • Love it! Love it! x 1
    • List
  4. Gyro Gearloose

    Gyro Gearloose Audiosexual

    Joined:
    Jul 8, 2019
    Messages:
    4,237
    Likes Received:
    1,846
    Location:
    Germany
    can someone pls state a few really good FIR EQ's pls ?
     
  5. No Avenger

    No Avenger Moderator Staff Member

    Joined:
    Jul 19, 2017
    Messages:
    8,975
    Likes Received:
    6,172
    Location:
    Europe
    ReaFir (stock Reaper) and probably most versatile due to freely adjustable phase align DMGAudio EQuilibrium.
     
    • Like Like x 3
    • Winner Winner x 1
    • Useful Useful x 1
    • List
  6. mild pump milk

    mild pump milk Russian Milk Drunkard

    Joined:
    Mar 29, 2014
    Messages:
    2,695
    Likes Received:
    2,274
    Location:
    Russia
    FIR works worse with lows, narrow bands and harmonics, can be solved with higher resolutions, longer impulse response. Worst for DC Offset.
    IIR works worse with very steep filters, especially at near nyquist area, can be solved with oversmpling, higher sample rates. Best for dc offset and works surgically better with lows, harmonics.
     
    Last edited: Aug 23, 2019
    • Like Like x 2
    • Winner Winner x 1
    • Interesting Interesting x 1
    • Love it! Love it! x 1
    • List
  7. Xupito

    Xupito Audiosexual

    Joined:
    Jan 21, 2012
    Messages:
    6,983
    Likes Received:
    3,853
    Location:
    Europe
    MeldaProduction has very cool EQs. MFreeForm EQ is almost literally only a FIR filter.
     
    • Like Like x 2
    • Agree Agree x 1
    • Interesting Interesting x 1
    • List
  8. Xupito

    Xupito Audiosexual

    Joined:
    Jan 21, 2012
    Messages:
    6,983
    Likes Received:
    3,853
    Location:
    Europe
    I knew the theory behind but not the harmonic difference. Is it related to the worse/better narrow band performance of FIR/IIR filters? Something else... both...
     
  9. mild pump milk

    mild pump milk Russian Milk Drunkard

    Joined:
    Mar 29, 2014
    Messages:
    2,695
    Likes Received:
    2,274
    Location:
    Russia
    If you choose 1024 IR length (FIR on EQuilibrium) with 96kHz sample rate, and very super narrow bell / notch cut with small harmonic to cut, it may not work. First, because IR length is too short, it will not cut the frequency, or will do it worse. Second, sample rate is too long. 2048 at 44100 is same as 4096 at 88200.
    IIR cuts more better such things, but may creates other imperfections.
    DC offset is better to see. IIR does DC cut off to -inf even with minimal settings, such as 5Hz and 6dB/oct, while FIR does it worse even with 25 Hz, steep filter and longer IR length, so it suppresses, not cut at all. Why? Because FIR doesn't work with near 0 Hz area, as I think it starts to work with 1 Hz and higher, but you need extremely highest IR length. So you will get phase shift shit, more ringing, more cpu overkill etc. Just use IIR mode for that and it is done. Same with FIR and harmonics, more length, more narrow frequencies you can work with, 433,1 Hz or 433,2 Hz or between. Wider - less ir length.
    Kaiser mode all the way in EQuilibrium. 65536 ir length as staring point. Recommended by Dave Gamble. I can post all the comment to see what setting he uses, what for, how, etc. differences between iir vs fir on material etc
     
    • Like Like x 1
    • Love it! Love it! x 1
    • List
  10. Can't I just have a treble knob without any sides?
     
  11. Gyro Gearloose

    Gyro Gearloose Audiosexual

    Joined:
    Jul 8, 2019
    Messages:
    4,237
    Likes Received:
    1,846
    Location:
    Germany
    pls do that
     
  12. mild pump milk

    mild pump milk Russian Milk Drunkard

    Joined:
    Mar 29, 2014
    Messages:
    2,695
    Likes Received:
    2,274
    Location:
    Russia
    Dave Gamble (DMGAudio) posted on Gearslutz:


    There are no de-facto best settings for mastering. As a rule, I'd probably stick it in FIR mode with a Kaiser window (with the tuning at 0.5, which I set as default deliberately), with an IR length of 65536, in Free Phase mode, and maybe some padding if I was doing anything crazy. If your mastering is gentle, then these settings should be sane enough, and it'll be diminishing returns increasing from here.

    Also, I would suggest using minimum phase for low frequency stuff and linear phase for mid and highs, which is achieved with Free Phase by having the control handles start at the bottom of the screen and end up in the middle.

    If you have something a bit nasty to deal with, using higher settings should make your plight that little easier. The deal is that you can buy your way out of problems by spending CPU, and if you've used EQuilibrium for a while, you'll know what I'm talking about.

    Specific answers:
    FIR vs IIR - FIR allows you to dial-in the phase response, and give you a lot more control generally. For mastering, /try/ IIR, but 9 times out of 10 you'll likely end up FIR just because it gives you more to play with.

    Phase - for mastering, start in Free. If you find you always prefer the sound with the bands in the middle, just use Linear. If you prefer the bands at the bottom, just use Analogue. If you prefer bands all over the place, stay in Free! (=me)

    Window Shape - Kaiser all the way. Seriously, that guy did some very clever maths. Use it! It's parametric so you can play with it and get a feel for what it does. So, the window shape trades off between tightness in the time domain+ smoothness in the frequency domain vs slow decays in the time domain+sharp edges in the frequency domain. If you're notching something, you need the latter. If you're mastering, you most likely want the former. As you sweep the parameter around, you trade from one to the other. The other shapes do the same thing - they give you a specific balance between tight time-domain response and definition in the frequency domain. For high IR lengths, this stuff is all pretty subtle, so test it with a short IR. I included the full set of common window shapes, because it was easy, nice to be able to explore, and I suspected someone would ask at some point.

    Padding - quite a fun trick this one. When it designs the filter, it will use a "virtual" IR length of padding * ir length (so, with padding x4 it'll design an impulse response four times as long). This dramatically reduces the (this is already too technical, I'm going to smudge language a bit) 'wrap-around' of the impulse response, because it gets unpacked into a bigger box. Then we take the part where all the action is, window /that/, and use that as the IR. So, you trade off spending CPU for computing the IR (which is every time you adjust the EQ) in exchange for a more accurate calculation of the IR.
     
    • Like Like x 2
    • Interesting Interesting x 1
    • Useful Useful x 1
    • List
  13. Gyro Gearloose

    Gyro Gearloose Audiosexual

    Joined:
    Jul 8, 2019
    Messages:
    4,237
    Likes Received:
    1,846
    Location:
    Germany
    :thanks::drunks:
     
    • Agree Agree x 1
    • Love it! Love it! x 1
    • List
  14. Xupito

    Xupito Audiosexual

    Joined:
    Jan 21, 2012
    Messages:
    6,983
    Likes Received:
    3,853
    Location:
    Europe
    Many tanks @mild pump milk . Some of the things I understood explain some of the reputation of DMG equalizers.
     
    • Like Like x 2
    • Interesting Interesting x 1
    • List
  15. mild pump milk

    mild pump milk Russian Milk Drunkard

    Joined:
    Mar 29, 2014
    Messages:
    2,695
    Likes Received:
    2,274
    Location:
    Russia
    Also, to add: Free Phase at the bottom is Analogue Phase (neither Minimum Phase, nor Zero-Latency Analogue Phase), at the center is Linear Phase, at the top - reversed Analogue Phase. Reversed Analog Phase as I understood, is useful for Reverse sounds, woops, reversed fx, so natural preringing-only for reversed sound (from starting tail to ending start), because processing reversed sounds with usual analog and minimum phase adds post-ringing to the end of sample, which is start in original non-reversed-yet sample.
    Boom - for analog phase eqs
    mooB - for reversed analog phase eqs
    Or process Boom in analog phase mode, render, and then reverse this sample - and you will get mooB like it would be processed with reversed analog phase mode.

    The logic is clear and obvious and more natural. But in real world... It is interesting... How Pink Floyd used eqs on their reversed drums in Meddle?
     
    Last edited: Aug 24, 2019
  16. mild pump milk

    mild pump milk Russian Milk Drunkard

    Joined:
    Mar 29, 2014
    Messages:
    2,695
    Likes Received:
    2,274
    Location:
    Russia
    And more info: it is too real to make IIR fully linear phase yeaaah! (offline, partly manually)
    :)
     
    Last edited: Aug 24, 2019
  17. Gyro Gearloose

    Gyro Gearloose Audiosexual

    Joined:
    Jul 8, 2019
    Messages:
    4,237
    Likes Received:
    1,846
    Location:
    Germany
    :beg:
     
    • Agree Agree x 1
    • Funny Funny x 1
    • List
Loading...