Lab # 07 IIR PDF
Lab # 07 IIR PDF
Remarks: …………………………………………………
Instructor’s Signature:………….………………….
1
Experiment # 07
Implementation of Infinite Impulse Response (IIR) Filter using
Fixed Point Arithmetic (Qn.m)
Objectives
1. Gain familiarity with the number representation method i.e. fixed point and floating point.
2. Learn how to convert IIR filter coefficient from floating point representation into fixed point
representation.
3. Learn how to implement FIR filter using finite precision arithmetic.
Introduction
Digital signal processing can be separated into two categories - fixed point and floating point.
These designations refer to the format used to store and manipulate numeric representations
of data.
1) Truncation operation
2) Rounding operation.
Truncation operation
In this operation, the number x is truncated beyond B significant bits (i.e., the rest of the bits
are eliminated) to obtain QT[x]. In MATLAB, to obtain a B-bit truncation, we have to first scale
the number x upward by 2B, then use the fix function on the scaled number, and finally scale
the result down by 2−B. Thus the MATLAB statement xhat = fix(x*2B)/2B; implements the desired
operation.
Rounding operation
In this operation, the real number x is rounded to the nearest representable level, which we will
refer to as QR[x]. In MATLAB, to obtain a B-bit rounding approximation, we have to first scale
the number x up by 2B, then use the round function on the scaled number, and finally scale the
result down by 2−B. Thus the MATLAB statement xhat = round(x*2B)/2B; implements the desired
operation.
Filters
Filtering is a class of signal processing, the defining feature of filters being the complete or
partial suppression of some aspect of the signal. Most often, this means removing some
3
frequencies and not others in order to suppress interfering signals and reduce background
noise.
The finite word-length arithmetic needed for processing these numbers is implemented using
two different approaches, depending on the ease of implementation and the accuracy as well
as dynamic range needed in processing. The fixed-point arithmetic is easy to implement but has
only a fixed dynamic range and accuracy. The floating-point arithmetic, on the other hand, has
a wide dynamic range and a variable accuracy (relative to the magnitude of a number) but is
more complicated to implement and analyze.
• Approximations:
Once the specifications are defined, we use various concepts and mathematics that we studied
so far to come up with a filter description that approximates the given set of specifications. This
step is the topic of filter design.
4
• Implementation:
The product of the above step is a filter description in the form of a difference equation, a
system function H(z), or an impulse response h(n). From this description, we implement the
filter in hardware or through software on a computer.
1) Design of Filter in Analog Domain and then converting it into Digital Domain
The basic technique of IIR filter design transforms well-known analog filters into digital filters
using complex-valued mappings. The advantage of this technique lies in the fact that both
analog filter design (AFD) tables and the mappings are available extensively in the literature.
This basic technique is called the A/D (analog -to- digital) filter transformation. However, the
AFD tables are available only for low pass filters. We also want to design other frequency
selective filters (high pass, band pass, band stop, etc.). To do this, we need to apply frequency
5
band transformations to low pass filters. These transformations are also complex-valued
mappings, and they are also available in the literature.
The main problem with these approaches is that we have no control over the phase
characteristics of the IIR filter. Hence IIR filter designs will be treated as magnitude-only
designs. More sophisticated techniques, which can simultaneously approximate both the
magnitude and the phase responses, require advanced optimization tools.
Where N is the order of the filter and Ωc is the cutoff frequency in rad/sec. The plot of the
magnitude-squared response is as follows.
6
To determine the system function Ha(s), we put above equation in the form below to obtain
A stable and causal filter Ha(s) can now be specified by selecting poles in the left half-plane, and
Ha(s) can be written in the form
Where N is the order of the filter, ɛ is the passband ripple factor, which is related to Rp, and TN
(x) is the Nth-order Chebyshev polynomial given by
7
3) Elliptic Low Filters
These filters exhibit equiripple behavior in the passband as well as in the stopband. They are
similar in magnitude response characteristics to the FIR equiripple filters. Therefore, elliptic
filters are optimum filters in that they achieve the minimum order N for the given specifications
(or alternately, achieve the sharpest transition band for the given order N). These filters, for
obvious reasons, are very difficult to analyze and, therefore, to design. It is not possible to
design them using simple tools, and often programs or tables are needed to design them. The
magnitude-squared response of elliptic filters is given by
Where N is the order, ɛ is the passband ripple (which is related to Rp), and UN(.) is the Nth-order
Jacobian elliptic function.
8
response from analog to digital filter, then we obtain a technique called impulse invariance
transformation. If we want to convert a differential equation representation into a
corresponding difference equation representation, then we obtain a finite difference
approximation technique. One technique, called step invariance, preserves the shape of the
step response. Another technique that is similar to the impulse invariance is the matched-z
transformation, which matches the pole-zero representation. The most popular technique used
in practice is called a Bilinear transformation, which preserves the system function
representation from analog to digital domain. On summary we have following techniques.
1) Impulse Invariance Transformation (IIT)
2) Finite Difference Approximation Technique (FDAT)
3) Step Invariance (SI)
4) Matched-Z Transformation(MT)
5) Bilinear Transformation (BLT)
5. There is also another set of filter functions—namely, the buttord, cheb1ord, cheb2ord, and
ellipord functions—that can provide filter order N and filter cutoff frequency ωn, given the
specifications.
9
IIR Filter Realization
Difference equation for IIR filter which are also called recursive filter is given below.
System function or transfer function can be obtained by taking the z-transform of above
difference equation.
There are many ways to implement (realize) an IIR filter, which are given below.
1) Direct Form 1
2) Direct Form 2 (Canonic Form)
3) Transposed Direct Form
4) Cascade Form
5) Parallel Form
DF -I, DF -II, TDF -I and TDF -II all suffers from coefficient quantization. A filter designed using
double precision may get unstable after quantization. So conversion to second order sections
(sos) before quantization is highly desired and quantization of coefficient effects only the
conjugate pole pair.
10
Lab Task:
Write a Verilog code to implement a given eighth - order IIR filter as shown in fig-9 and also
write a test bench for exhaustive testing.
The required parameters for the coefficients and input are given in table:
b0=8'd7, b1=8'd0, b2=8'd0, b3=8'd0, b4=8'd0, b5=8'd0, b6=8'd0, b7=8'd0, b8=8'd0;
a1=8'd46, a2=8'd32, a3=8'd17, a4=8'd0, a5=8'd17, a6=8'd32, a7=8'd46, a8=8'd52;
Procedure:
1) Write a Verilog code and a appropriate test bench for the above filter accordingly.
2) Verify your simulations with the help of calculations performed.
Home Task
Write a Verilog code to implement a second-order low pass IIR filter as given above and also
write a test bench for exhaustive testing.
11
Filter coefficient
b0= 0.0675 (), b1= 0.1349 b2= 0.0675
a1= -1.1430 a2= 0.4128
x=Q1.3; y=Q1.15
Note: Choose an appropriate Qn.m format for filter coefficient. Fractional bit (m) should be less
than or equal to 15 for maximum precision.
Procedure:
1) First of all, set the formats for each coefficient, input and output.
2) Perform the required arithmetic operations after conversions (floating to fixed point) on
page.
3) Write a Verilog code and an appropriate test bench for the above filter accordingly.
4) Verify your simulations with the help of calculations performed.
Labs Rubrics
Experiment # 07
Implementation of Infinite Impulse Response (IIR) Filter using
Fixed Point Arithmetic (Qn.m)
12
Lab Evaluation Rubrics
# Qualities & Criteria 0 < Poor <=40 40< Satisfactory <= 70 70 < Good <= 90 90< Excellent <=100
No Tasks were Some tasks were Few tasks were left All tasks completed in
completed/ minimal completed. Could not to be completed. due time. All goals
ER1 Task Completion effort shown justify the reasons for Provided achieved.
uncompleted tasks acceptable
and goals. justification for the
uncompleted tasks
and goals.
ER3 Test Bench No test vectors applied/ Test vectors applied Test vectors applied Test vectors
minimal effort shown meeting some of the fulling most of the appropriately applied
requirements requirements
ER7 Code indentation, No indentation of code, Computationally Working code and Good structure,
optimization and no optimization and no complex routine with good indentation or optimized code and
descriptive variable descriptive variable improper indentation structure, but not good variable names
name names/ minimal effort and variable names optimized resulting and comments
shown in unnecessary
computations
ER9 Results and Plots Unable to produce any Inaccurate plots and Correct plots Good presentation of
plots or results /minimal results without any the correct plots with
efforts shown necessary proper labels,
identifying features captions & visibility
such as labels,
captions & visibility
Format/Layout & Follows poorly the Follows, for some Follows, for most Closely follows all the
Organization requirement related to part, all the part, all the requirements related
RR1 format and layout. The requirements related requirements to format and layout.
report is disorganized to to format and layout. related to format Written work is well
the extent that it The organization is and layout. The organized and easy to
prevents understanding unclear organization is understand
of he content generally good, but
some parts seem
out of place
13