Lab 5
Lab 5
Types of filters
Filter can be classified into following types
1
FIR filters
A finite impulse response filter can easily be understood by simply its name.
A filter whose response to an input impulse will be of finite length. In simple
words, FIR filters gives a finite duration output in response to an impulse as
we will see shortly in the example below. Comping over to the order of FIR
filters. The order of a filter is defined as the order of its transfer function. For
an Nth order FIR filter, the output is only dependent of the first N input
samples. We will design a second order FIR filter in this tutorial. A general
design of a FIR filter is shown in the figure below,
It is now evident that we can realize the recursive filter by a superposition of a non-
recursive and a recursive part. With the elements given above, this results in the
following block-diagram:
2
Direct form I filter :
This representation is not canonical since N+MN+M unit delays are required
to realize a system of order NN. A benefit of the direct form I is that there is
essentially only one summation point which has to be taken care of when
considering quantized variables and overflow. The output signal y[k]y[k] for
the direct form I is computed by realizing above equation. The block diagram
of the direct form I can be interpreted as the cascade of two systems.
Denoting the signal in between both as w[k]w[k] and discarding initial values
we get where h1[k]=[b0,b1,…,bM]h1[k]=[b0,b1,…,bM] denotes the impulse
response of the non-recursive part and h2[k]=[1,−a1,…,−aN]h2[k]=[1,−a1,…,
−aN] for the recursive part. From the last equality of the second equation and
the commutativity of the convolution it becomes clear that the order of the
cascade can be exchanged.
Direct Form II filter:
The direct form II is yielded by exchanging the two systems in above block diagram
and noticing that there are two parallel columns of delays which can be combined,
since they are redundant. For N=MN=M it is given as:
Other cases with N≠MN≠M can be considered for by setting coefficients to zero. This
form is a canonical structure since it only requires NN unit delays for a recursive
filter of order NN. The output signal y[k]y[k] for the direct form II is computed by
the following equations The samples w[k−m]w[k−m] are termed state (variables) of
a digital filter.
3
Designing FIR Filter in Simulink Matlab
Lets’ now design a second order FIR filter using the system of the filter
given in the equation below.
Above is given a filter of 2nd order. We will now compare the above
equation with a general equation given below, to find the co-efficient
b0 , b1 ,b2 .
b0 = 2, b1 = 1,b2 =2 .
Now, lets’ design this filter in MATLAB’s simulink. First of all open
MATLAB and then simulink as we have been doing in previous
tutorials and create a blank model to design a simple FIR filter. Open
the library browser of simulink and from the commonly used blocks,
select the constant block as shown in the figure below. This block will
serve as the co-efficient of the equation.
4
Next, we will be needing a delay block which will serve as the x[n-1]
and x[n-2] delayed samples. The order of the filter will decide the
number of delay blocks to be used in the filter design. In our example
the order of filter is 2 and hence the number of delay block. From the
commonly used blocks section, select the delay block and place it on
the model as shown in the figure below:
5
The number of stages of an FIR filter to be designed will also depend
on the order of the filter. If the order of the filter is N then the number
of stages to be used in the filter design will be N+1. In our case the
order of the filter is 2 and hence the stages will be 3. At the end of the
filter stages we will have to sum up the output of all the stages as is
obvious from the equation of our system. For this summation process,
we have to use a sum block. From the Math operation section in
simulink library browser, select the sum block and add it to the model
as shown in the figure below:
6
Also in order to multiply the co-efficient of each stage with the delayed
input, we have to use some product block. In the library browser from
the section of Math operations select the Product block and place it in
the model as shown in the figure below:
7
Next step is to add some input source in order to see the response of
the system correctly. The input source we will use here is Repeating
Sequence Stairs. The purpose of using this block is to generate an
impulse as we will see shortly how to do so. From the sources section
of the library browser of simulink, select Repeating Sequence Stairs
block and add it to model as shown in the figure below:
8
In order to display the output of the filter, we also need some kind of
oscilloscope to display input along side of output. From the sinks
section of library browser select scope and add it to model as shown in
the figure below:
9
Now lets move to the model we have created in the start to jump
towards the designing part of the filter. As we have discussed
previously, our filter will have three stages. We will design each stage
step by step. First of all place the input source at the left and double
click on it to change its input to an impulse. In the parameter block add
the sequence of input as shown below:
10
Now using the equation given for the filter, we will start designing
from left to right. The first addend of the equation will make the first
stage as shown in the figure below;
The same input will be then used with a single delay to make the
second stage and multiplied with the constant value of one as shown in
the figure below:
11
Same will happen in the case of third stage with one more delay block
at the output of the first delay block to provide the 2 times delayed
input i.e. x[n-2] as shown in the figure below:
Now the output of all three stages will be added using sum block. But
first change the number of inputs of the sum block as we have done
previously. And at the output of the sum block connect a 2 input scope
(one for the input and one for the output) as shown in the figure below;
12
Now change the simulation stop time to 1 as we have done before and
run the simulink model. After the completion of running double click
on the scope and the output of the filter will look like the one shown in
the figure below;
13
LAB TASKS
Assignment 1:
Design a third order FIR filter of the system given in the equation below.
(Hint: Number of delay blocks to be used will be 3)
14
Assignment 2:
Implement the following using DF-I and DF-II FIR filter structures in
Simulink.
15