The class of infinite-length impulse response (IIR) filters
can be characterized in the three domains: the time domain
via the impulse response \(h[n]\), the frequency domain
via the frequency response, and the \(z\)-domain via
poles and zeros.
This demo shows plots in the three domains for a variety
of choices of the feedback coefficients in first- and second-order
IIR filters.
Similar plots can be generated interactively by using the
MATLAB graphical user interface tool called
PeZ.

## First-Order IIR Filters

Earlier we learned that first-order IIR filters (also
called feedback filters) of the
form:
\(y[n]=a^n\) for \(n \geq 0\)
\(y[n] = a^n = (r e^{j\theta})^n = r^n e^{j\theta n}\) for \(n \geq 0\)

## Examples

In the first example let's set the feedback coefficient \(a\) to be:
\(a=1 e^{j \pi/4 } \)

Below is the resultant plot. Note that the "period" of the sinusoid is 8 samples and the digital frequency is therefore \(\frac{2\pi}8\).

Below is the resultant plot.

## Second-Order IIR Filters

We also learned about second-order IIR (feedback) filters.
Assuming that the poles of the IIR filter are complex, we know
that the impulse response will have the following form:
$$h[n] = A r^n \cos(n\theta + \phi).$$
Assuming the filter coefficients to be strictly real implies that the
poles of the filter will occur in conjugate pairs:
\(p_1 = r e^{j\theta}\) and \(p_2 = r e^{-j\theta}\)
$$a_1 = 2r\, \cos \theta$$
$$a_2 = -r^2$$

## Example:\(a_2\) Fixed, Variable \(a_1\)

In these examples, we will fix \(a_2 = -1\)
and observe the oscillator output and pole/zero plot as \(a_1\)
is varied from \(2\, \cos(\frac{\pi}6)\) to \(2\, \cos(\frac{\pi}3)\).
\(a_1 = 2\, \cos(\frac{\pi}6)\) and \(a_2 = -1\)

\(a_1 = 2\, \cos(\frac{\pi}4)\) and \(a_2 = -1\)

\(a_1 = 2\, \cos(\frac{\pi}3)\) and \(a_2=-1\)

## Example: \(a_1\) Fixed, Variable \(a_2\)

In these examples we will fix
\(a_1 = 2\, \cos(\frac{\pi}4)\)
and observe the oscillator output and pole/zero plot as
\(a_2\) is varied from \(-0.8\) to \(-1.2\).

\(a_1 = 2\, \cos(\frac{\pi}4)\) and \(a_2 = -0.8\)

\(a_1 = 2\, \cos(\frac{\pi}4)\) and \(a_2 = -1\)

\(a_1 = 2\, \cos(\frac{\pi}4)\) and \(a_2 = -1.2\)

Below are a few examples using the MATLAB tool PeZ.## Example: Second Order Oscillator

Using PeZ in MATLAB we can easily generate complex pole pairs.
For an oscillator that does not decay we must be careful to place
the poles on the unit circle. We will use the
edit by coordinate
feature of PeZ to insure proper pole placement:

## Example: Decaying Oscillator

By choosing \(r<1\), we
can generate a sinusoid that decays over time. As an illustration, lets
start with previous example and observe how the impulse reponse
is affected by decreasing the magnitude \(r\) from
from \(1\) to \(0.925\) (the angle is held fixed at \(n/8\):

## Example: Growing Oscillator

By choosing \(r<1\), we
can generate a sinusoid that grows over time. As an illustration, lets
start with previous example and observe how the impulse reponse
is affected by increasing the magnitude \(r\) from from \(1\) to \(1.075\):

$$y[n]=a\, y[n-1] + x[n]$$

have an impluse response given by:

Usually the parameter \(a\) is taken to be a real number. However, if \(a\) is chosen to be complex, then the impulse response of the first-order IIR filter can be written as:

Thus, an oscillating signal (sinusoid) can be produced by specifying
the appropriate value for \(a\) and taking either the real
or imaginary part of the impulse response.

In MATLAB we can generate the output using the **filter**
command. Here are the series of MATLAB commands that will generate
the first order oscillator:

```
```

```
imp=([0:33]==0); % <-- length 34 impulse
y=filter(1,[1 -exp(j*2*pi/8)],imp); % <-- filter the impulse
plot(real(y)) % <-- take the real part
```

```
```

Below is the resultant plot. Note that the "period" of the sinusoid is 8 samples and the digital frequency is therefore \(\frac{2\pi}8\).

Let's try another example. This time we'll use
\(a=1 e^{j \pi/10}\)

```
```

```
imp=([0:40]==0); % <-- length 41 impulse
y=filter(1,[1 -exp(j*2*pi/20)],imp); % <-- filter the impulse
plot(real(y)) % <-- take the real part
```

```
```

Below is the resultant plot.

This time the frequency of the oscillator is
\(\frac{2\pi}{20}\).
Clearly the angle of the feedback term is equal to the frequency of
oscillation.

Expanding the factored polynomial shows the relationship between the filter coefficients, \(a_1\) and \(a_2\), and the magnitude and phase of the poles:

Remember, the above relationship holds only when the poles are conjugate
pairs. By setting \(a_2 = -1\) we
can ensure that the oscillator does not decay with time. Now by
simply varying \(a_1\) we can control
the frequency of oscillation. Below are some examples that
demonstrate the relationship between filter coefficients, pole
locations and frequency of oscillation.

Note how the magnitude of the poles remains equal to one but the
angle changes with \(a_1\).
Also note how the amplitude of the oscillator changes for
different \(a_1\). This is because \(a_1\) and
\(a_2\) do not provide independent
control over the amplitude and frequency of the ocsillator.

Note that as \(a_2\) is changed the the poles move along a vertical line
that intersects the \(x\)-axis at \(x = \cos(\frac{\pi}4)\)
The filter coefficient
\(a_2\) can also be seen to affect the frequency of oscillation. This
is because \(a_1\) and \(a_2\) do not provide independent
control over the amplitude and frequency of the ocsillator. Note
also that if \(a_2\) has magnitude less than one the oscillator
decays while if the magnitude of \(a_1\)
is greater than one the oscillator grows over time.

Below are a few examples using the MATLAB tool PeZ.

Note the poles have magnitude equal to one and angles equal to \(\frac{\pi}8\). Pez returns the following for plots for the impulse and frequency response:

While it is difficult to measure the frequency of the oscillator
from the above graph it can be seen to be approximately
\(\frac{2\pi}{16}\), which is the value we expected.

Here are the plots for \(r=1\):

Now here are the plots for \(r=0.975\):

Now here are the plots for \(r=0.95\):

Now here are the plots for \(r=0.925\):

Note how the amplitude of the impulse reponse decays faster with smaller values of \(r\).

Here are the plots for \(r=1\):

Now here are the plots for \(r=1.025\):

Now here are the plots for \(r=1.05\):

Now here are the plots for \(r=1.075\):

Note how the amplitude of the impulse reponse decays faster with smaller values of \(r\).