Filters
Filters
Filters
setting a weighted sum of outputs equal to a weighted sum of inputs. This is like the
equation that we gave earlier for the causal FIR filter, except that in addition to the
weighted sum of inputs, we also have a weighted sum of outputs.
Adopting the convention that a(1) = 1 (e.g. by scaling other a's and b's), we can get rid of
the 1/a(1) term:
If all the a(n) other than a(1) are zero, this reduces to our old friend the causal FIR filter.
This is the general case of a (causal) LTI filter, and is implemented by the MATLAB
function "filter."
Let's look at the case where the b coefficients other than b(1) are zero (instead of the FIR
case, where the a(n) are zero):
In this case, the current output sample y(n) is calculated as a weighted combination of the
current input sample x(n) and the previous output samples y(n-1), y(n-2), etc. To get an
idea of what happens with such filters, let's start with the case where:
That is, the current output sample is the sum of the current input sample and half the
previous output sample.
We'll take an input impulse through a few time steps, one at a time.
Step 1
MATLAB n: ? 1 2 3 4 5 6 7 8
__________________________________________________________________
Input: 1 0 0 0 0 0 0 0
Output: 0 0 0 0 0 0 0 0 0
__________________________________________________________________
|
Result: 1
Step 2
MATLAB n: ? 1 2 3 4 5 6 7 8
_________________________________________________________________
Input: 1 0 0 0 0 0 0 0
Output: 0 1 0 0 0 0 0 0 0
_________________________________________________________________
|
Result: .5
Step 3
MATLAB n: ? 1 2 3 4 5 6 7 8
________________________________________________________________
Input: 1 0 0 0 0 0 0 0
Output: 0 1 .5 0 0 0 0 0 0
________________________________________________________________
|
Result: .25
Step 4
MATLAB n: ? 1 2 3 4 5 6 7 8
________________________________________________________________
Input: 1 0 0 0 0 0 0 0
Output: 0 1 .5 .25 0 0 0 0 0
|
Result: .125
It should be clear at this point that we can easily write an expression for the nth output
sample value: it is just
.5^(n-1)
Since what we are calculating is the impulse response of the system, we have
demonstrated by example that the impulse response can indeed have infinitely many non-
zero samples.
To implement this trivial first-order filter in MATLAB, we could use "filter". The call
will look like this:
r = rand(1,6)
s = rand(1,6)
filter([1 0],[1 -.5],r+s)
filter([1 0],[1 -.5],r) + filter([1 0],[1 -.5],s)
For a more general approach, consider the value of an output sample y(n).
It is x(n)+.5*y(n-1),
and y(n-1) in turn is
x(n-1)+.5*y(n-2),
and y(n-2) in turn is
x(n-2)+.5*y(n-3), and so on.
or again as
y(n)=x(n)+.5*x(n-1)+.25*x(n-2)+.125*x(n-3)+...
This is just
y(n) = .5^0 * x(n) + .5^1 * x(n-1) + .5^2 * x(n-2) + .5^3 * x(n-3) + ...
or
This is just like our old friend the convolution-sum form of an FIR filter, with the impulse
response provided by the expression .5^k, and the length of the impulse response being
infinite. Thus the same arguments that we used to show that FIR filters were linear will
now apply here.
So far this may seem like a lot of fuss about not much. What is this whole line of
investigation good for?
It's not a big surprise that we can calculate a sampled exponential by recursive
multiplication. Let's look at a recursive filter that does something less obvious. This time
we'll make it a second-order filter, so that the call to "filter" will be of the form
Let's set the second output coefficient a2 to -2*cos(2*pi/40), and the third output
coefficient a3 to 1, and look at the impulse response.