# Filters¶

This section of the library includes digital filters for performing digital signal processing operations.

## Filter (2, 2)¶

The Filter (2, 2) component implements a second-order IIR filter, defined by the difference equation

\begin{split}\begin{align} y[n] = \frac{1}{a_0}(& b_0 x[n] + b_1 x[n-1] + b_2 x[n-2] \\ & - a_1 y[n-1] - a_2 y[n-2]). \end{align}\end{split}

## FIR Filter¶

The FIR Filter component implements a general FIR filter, defined by the difference equation

$y[n] = \sum_{i=0}^N b_i x[n-i].$

The filter order $$N$$ is determined polymorphically by the type of the coefficient array $$b$$. The implementation of the FIR Filter component simply computes the dot product of $$b$$ with the output of a Shift Register component.

For small numbers of coefficients, the $$b$$ array can be written directly in the containing diagram by using the Pack Block primitive with Literal primitives as inputs. For larger coefficient arrays, it is easier to create a case table and use it in the containing diagram with an Index primitive as the table input.

## Filter¶

The Filter component implements a general IIR filter, defined by the difference equation

$y[n] = \left(\sum_{i=0}^N b_i x[n-i]\right) - \left(\sum_{j=1}^M a_j y[n-j]\right).$

The feedback filter order $$M$$ and feedforward filter order $$N$$ are determined polymorphically by the types of the coefficient arrays $$a$$ and $$b$$, respectively. For the sake of clarity of implementation, this component does not include an $$a_0$$ parameter; the coefficients are assumed to be normalized so that $$a_0 = 1$$.

This is a general filter component designed to allow writing many common types of 1-D linear filter. The Filter (2, 2) and FIR Filter components provide special cases that have simpler implementations than this component.