轉載、簡譯 FIR VS IIR

轉載、簡譯 FIR VS IIR

4 人贊了文章Difference Between FIR and IIR Filters

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.

本文主要闡述FIR相對於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 isnt 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.

由於FIR濾波器是被合成的,所以理論上所有的濾波器的響應都可以用FIR結構來實現,只要階數不是問題。

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.

IIR濾波器受限於S域的多項式所確定的響應,很難生成自定義的濾波器

It is quite possible however that the most important difference between an IIR and FIR isnt 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.

FIR和IIR最重要的差別在於濾波器的實現,FIR可以用整數運算實現。

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 cant be implemented in integer math because the IIR coefficients cant be scaled to integer values without having the filters math calculations explode (the problem is with the feedback coefficients). For example, scaling the coefficients by 16, which wont create nearly enough significant digits for filtering, will cause the calculations to go exponential. Try it.

IIR濾波器無法用整數運算實現,由於反饋係數的存在,IIR係數無法放大到整數值。

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 isnt 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 filters 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).

IIR在knee點更尖銳,且過渡帶更陡

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.

IIR需要更少的乘法和加法運算,FIR的群延時比較大,但群延時為常數;IIR群延時更小,但不是常數。

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 filters 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.

FIR和IIR最基本的差異在於群延時和脈衝響應。IIR是無限脈衝響應,所以模擬濾波器都是這種類型,FIR的階數就是長度,是有限長的

Closely related to the impulse response is the filters 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.

和脈衝響應密切相關的是階躍響應。從圖上可以看出,FIR的脈衝比IIR來的晚,這可以從群延時的比較得出。

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 filters group delay characteristics, and the slope of the filters 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.

在階躍響應上,overshoot和ringing是濾波器的群延時和轉換帶的坡度的函數。典型的FIR有常數群延時,這有助於減小階躍響應中的ringing和overshoot。然而我們也可以選擇貝塞爾型IIR濾波器,其幾乎沒有ringing和overshoot。簡言之,ringing和overshoot和FIR和IIR結構無直接關係。

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.

在幅頻響應相似情況下,FIR一般會有更小的ringing和overshoot,因為它的群延時特性比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 filters 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.

需要再次強調的是FIR可以有和IIR一樣的脈衝響應,但這裡展示的是典型的FIR濾波器。典型的FIR濾波器的脈衝響應是對稱的,中心是(N-1)/2。典型的IIR脈衝響應開始更早,結束更晚。再次強調,ringing的差別和IIR或FIR無關,和選擇用來生成濾波器的原型(Butterworth,Chebyshev,Bessel)有關。

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.

用放大器電路實現的Butterworth濾波器可以和IIR數字濾波器有相同的特性。

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 cant 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.

IIR濾波器由於有反饋迴路,如果極點放置不合適,會導致不穩定。FIR永遠是穩定的,無論怎樣生成。

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 registers 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 filters 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.

IIR和FIR有個很重要的區別是,在處理信號時,濾波器產生的峰值不同。因為在階躍響應中存在overshoot,方波一般產生最大的峰值。FIR的峰值一般不超過2,IIR的取值可以從1.0到10000,甚至更高。峰值和多項式以及選擇性有非常大的關係。濾波器的選擇性越好,峰值越大。

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 MathNth Order Peak MathButterworth Low Pass6.5 (3 bits)194,806 (18 bits)Cheby Low Pass 0.2 dB Ripple94.3 (7 bits)120,684,358 (27 bits)Butterworth Band Pass13.9 (4 bits)6.134E14 (50 bits)Cheby Band Pass 0.2 dB Ripple44.9 (6 bits)1.982E29 (98 bits)

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 polynomials N roots is numerically difficult because of their close proximity to one another.

FIR濾波器經常採用N階實現。也可以採用2階級聯,但一般不需要,也比較麻煩

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.

IIR濾波器可以通過浮點運算實現。如果使用定點,應該用二階級聯來實現

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 cant settle at zero after the input goes to zero. The filters output may oscillate indefinitely(無限) because a small residual(殘餘) signal continues to circulate within the filter.

IIR濾波器在輸入為0時,輸出不能為0(這和寄存器大小有關,IIR不能清空寄存器)。濾波器可能無限震蕩,因為有小的殘餘信號在濾波器中持續運算。

Of course, an ideal IIR filters 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.

IIR濾波器的輸出理論上永遠不能為0,但這種情況僅限於寄存器有無限精度。受寄存器大小導致的截斷將限制脈衝響應的長度。Notch和high pass類型的IIR濾波器受此問題影響由為嚴重。

Pole Zero Locations

If you are somewhat new to filter design, you may be wondering how the filters pole zero locations affect the filters 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 filters 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.

FIR的響應和IIR有輕微的不同,這種不同隨FIR階數增加而減小到0.

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 isnt shown.

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.

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 projects 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.

Home Page IIR Filter Page FIR Filter Page Download Page.

Copyright 2013 Iowa Hills Software
推薦閱讀:

TAG:數字信號處理 | 音頻處理 | 數字濾波器 |