### IIR - infinite impulse response filter

Moving averages, summation
(AFL 4.0)

 SYNTAX IIR( input, b0 = 1, a1 = 0, b1 = 0, a2 = 0, b2 = 0, a3 = 0, b3 = 0, a4 = 0, b4 = 0 ) RETURNS ARRAY FUNCTION The function implements fast 4th-order infinite impulse response filter. Analytically it is: y[ n ] = b0 * x[ n ] + b1 * x[ n - 1 ] + b2 * x[ n - 2 ] + b3 * x[ n - 3 ] + b4 * x[ n - 4 ] + a1 * y[ n - 1 ] + a2 * y[ n - 2 ] + a3 * y[ n - 4 ] + a4 * y[ n -4 ]; AFL equivalent: ```y = x; // init so no glitches at the beginning appear for( n = 4; n < BarCount; n++ ) { y[ n ] = b0 * x[ n ] +            b1 * x[ n - 1 ] +            b2 * x[ n - 2 ] +            b3 * x[ n - 3 ] +            b4 * x[ n - 4 ] +            a1 * y[ n - 1 ] +            a2 * y[ n - 2 ] +            a3 * y[ n - 4 ] +            a4 * y[ n - 4 ]; }``` Filters of orders 3 and 2 can be implemented by leaving unneeded arguments at default value of zero. Coefficients b0, b1, b2, b3, b4 multiply the input signal x[n] and are referred to as the feedforward coefficients. Coefficients a1, a2, a3, a4 multiply the output signal y[n] and are referred to as the feedback coefficients. Pay careful attention to the sign of the feedback coefficients. Some design tools flip the sign of the feedback coefficients. In this case the feedback coefficients must be negated. This convention is used so feedback coefficients work the same as in AMA2 in case of first order filter, so IIR( array, factor, 1-factor ) is the same as AMA2( array, factor, 1-factor ) (with very minor difference is that IIR uses internally double precision arithmetic while AMA2 uses single precision) EXAMPLE ```// simple ema: factor = 2/(period+1); y = IIR( input, factor, 1- factor ); // wilders: factor = 1/period z = IIR( input, factor, 1-factor ); // Ehlers Supersmoother Periods = 10; c1 = 1.41421 * 3.14159 / Periods; c2 = 2.71828^-c1; a1 = 2 * c2 * cos( c1 ); a2 = -c2^2; b0 = (1 - a1 - a2)/2; b1 = b0; x = IIR( Close, b0, a1, b1, a2 ); Plot( x, "Super Smoother", colorRed );``` SEE ALSO AMA() function , AMA2() function

#### References:

The IIR function is used in the following formulas in AFL on-line library: