0% found this document useful (0 votes)
101 views

Lab # 07 IIR PDF

The document discusses implementing an infinite impulse response (IIR) filter using fixed point arithmetic. It covers converting IIR filter coefficients from floating point to fixed point representation and implementing the filter using finite precision arithmetic. Bit growth is identified as a critical issue in fixed point arithmetic operations like multiplication and addition. The document also provides an overview of IIR filter design procedures and techniques.

Uploaded by

Irfan Haider
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Lab # 07 IIR PDF

The document discusses implementing an infinite impulse response (IIR) filter using fixed point arithmetic. It covers converting IIR filter coefficients from floating point to fixed point representation and implementing the filter using finite precision arithmetic. Bit growth is identified as a critical issue in fixed point arithmetic operations like multiplication and addition. The document also provides an overview of IIR filter design procedures and techniques.

Uploaded by

Irfan Haider
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Sir Syed CASE Institute of Technology, Islamabad

Digital System Design Lab

Experiment # 07: Implementation of Infinite Impulse Response


(IIR) Filter using Fixed Point Arithmetic (Qn.m)

Name of Student: …………………………………………………….

Roll No.: …………………………………………………………………..

Date of Experiment: ………………………………………………….

Report submitted on: ………………………………………………..

Marks obtained: ………………………………………

Remarks: …………………………………………………

Instructor’s Signature:………….………………….

Semester VI- Spring 2020

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.

Floating Points Representation


With floating-point representation, the placement of the decimal point can ‘float’ relative to
the significant digits of the number.
A floating-point representation could in addition represent 1.234567, 123456.7,
0.00001234567, 1234567000000000 etc.
• Used where precision and dynamic range are important
• Most algorithms are developed in FP
• Ease of coding
• More Cost (Area, Speed, Power)

Fixed Point Representation


The term ‘fixed point’ refers to the corresponding manner in which numbers are represented,
with a fixed number of digits after, and sometimes before, the decimal point. For example, a
fixed-point representation with a uniform decimal point placement convention can represent
the numbers 123.45, 1234.56, 12345.67 etc.
• Place of decimal is fixed
• Simpler HW, low power, less silicon
• Converting FP simulation to Fixed-point simulation is time consuming

General Fixed Point Arithmetic


Using the discussion of integer arithmetic from the last section as a guide, we can extend the
fixed-point representation to arbitrary real (integer and fractional) numbers. We assume that a
given infinite-precision real number x is approximated by a binary number 𝑥̂ with the following
bit arrangement:
Where the sign bit ± is 0 for positive numbers and 1 for negative numbers, x represents either a
0 or a 1, and (.) represents the binary point. L entirely depends upon the range of integer and B
defines the precision of the fractional part. This representation is in fact 2’s complement format
for real numbers, as we will see. The total word length of the number 𝑥̂ is equal to L+B +1 bits.
We will prefer 2’s complement for representing fixed point number as almost all the current
processor implement signed arithmetic using this format.

Bit Growth in Fixed Point Arithmetic


From the discussion of number representations, it should be clear that a general infinite-
precision real number must be assigned to one of the finite representable numbers, given a
specific structure for the finite-length register (i.e., the arithmetic as well as the format). These
operations affect the accuracy as well as general characteristics of digital filters and DSP
operations. Bit growth is one of the most critical issues in fixed-point arithmetic. Multiplication
of an N-bit number with an M-bit number results in an (N+M)-bit number Multiplication of two
N1 and N2 bit numbers in Qn1.m1 and Qn2.m2 results in N1+N2 bit number. Q(n1+n2-
1).(m1+m2+1) for SxS and Q(n1+n2).(m1+m2) for the rest. Where as in addition results is
Qn.m= Q max(n1,n2).max(m1.m2). Usually, in practice, there are two different operations by
which this assignment is made to the nearest number or level:

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.

Infinite Impulse Response (IIR) Filter


In signal processing, infinite impulse response (IIR) filter is a filter whose impulse response (or
response to any finite length input) is of infinite duration, because IIR filters, which may have
internal feedback and may continue to respond indefinitely (usually decaying).
When finite-precision representation is used in its implementation, there are three possible
considerations that affect the overall quality of its output. We have to
1. Quantize the filter coefficients {ak, bk} to obtain their finite word-length representations
{𝑎̂k, b̂k}.
2. Quantize the input sequence x(n) to obtain 𝑥̂(n).
3. Consider all internal arithmetic that must be converted to their next best representations.

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.

IIR Filter Design Procedure


The design of a digital filter is carried out in three steps:
• Specifications:
Before we can design a filter, we must have some specifications. These specifications are
determined by the applications.

Figure-1: Filter Specification

• 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.

Figure-2: Design Flow for Digital Filter

Design Techniques for IIR Filter


There are three design techniques for FIR filter design, namely
1) Design of Filter in Analog Domain and then converting it into Digital Domain
2) Analytical Method
3) Algorithmic Method (Using CAD Tool which minimizes mean square error)

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.

Figure-3: Design Methodology for IIR Filter

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.

Characteristics of Prototype Analog Filter


IIR filter design techniques rely on existing analog filters to obtain digital filters. We designate
these analog filters as prototype filters. Three prototypes are widely used in practice.
1) Butterworth Low Pass Filter
2) Chebyshev Low Pass (Type I and II) Filter
3) Elliptic Low Pass Filter

1) Butterworth Low Pass


This filter is characterized by the property that its magnitude response is flat in both passband
and stopband. The magnitude-squared response of an Nth-order low pass filter is given by

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.

Figure-4: Magnitude Response Plot

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

2) Chebyshev Low Pass Filter


There are two types of Chebyshev filters. The Chebyshev-I filters have equiripple response in
the passband, while the Chebyshev-II filters have equiripple response in the stopband.
Butterworth filters have monotonic response in both bands. We noted that by choosing a filter
that has an equiripple rather than a monotonic behavior, we can obtain a lower-order filter.
Therefore, Chebyshev filters provide lower order than Butterworth filters for the same
specifications.
The magnitude-squared response of a Chebyshev-I filter is

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

Figure-5: Magnitude Plot for Chebyshev-I


The equiripple response of the Chebyshev filters is due to this polynomial TN(x). Its key
properties are (a) for 0 < x < 1, TN(x) oscillates between −1 and 1, and (b) for 1 < x < ꝏ, TN(x)
increases monotonically to ꝏ. There are two possible shapes of |Ha(jΩ)|2, one for N odd and
one for N even as shown above.
To determine a causal and stable Ha(s), we must find the poles of Ha(s)Ha(−s) and select the left
half-plane poles for Ha(s). The poles of Ha(s)Ha(−s) are obtained by finding the roots of

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.

Figure-6: Magnitude Response for Elliptic Filter

Phase Responses of Prototype Filters


Elliptic filters provide optimal performance in the magnitude-squared response but have highly
nonlinear phase response in the passband (which is undesirable in many applications). Even
though we decided not to worry about phase response in our designs, phase is still an
important issue in the overall system. At the other end of the performance scale are the
Butterworth filters, which have maximally flat magnitude response and require a higher-order
N (more poles) to achieve the same stopband specification. However, they exhibit a fairly linear
phase response in their passband. The Chebyshev filters have phase characteristics that lie
somewhere in between. Therefore, in practical applications, we do consider Butterworth as
well as Chebyshev filters, in addition to elliptic filters. The choice depends on both the filter
order (which influences processing speed and implementation complexity) and the phase
characteristics (which control the distortion).

Analog to Digital Filter Transformation Techniques


After discussing different approaches to the design of analog filters, we are now ready to
transform them into digital filters. These transformations are complex-valued mappings that
are extensively studied in the literature. These transformations are derived by preserving
different aspects of analog and digital filters. If we want to preserve the shape of the impulse

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)

MATLAB Toolbox for SP (Signal Processing) Applications


Now we will demonstrate the use of MATLAB’s filter design functions to design digital low pass
filters. These functions use the bilinear transformation technique.
1. [b, a]=butter(N, wn)
This function designs an Nth-order low pass digital Butterworth filter and returns the filter
coefficients in length N +1 vectors b and a. The filter order is given by Butterworth order
equation and the cutoff frequency wn is determined by the prewarping formula.

2. [b, a]=cheby1(N, Rp, wn)


This function designs an Nth-order low pass digital Chebyshev-I filter with Rp decibels of ripple
in the passband. It returns the filter coefficients in length N + 1 vectors b and a. The filter order
is given by its order equation, and the cutoff frequency wn is the digital passband frequency in
units of π.

3. [b, a]=cheby2(N, As, wn)


This function designs an Nth-order low pass digital Chebyshev-II filter with the stopband
attenuation As decibels. It returns the filter coefficients in length N + 1 vectors b and a. The
filter order is given by its order equation, and the cutoff frequency wn is the digital stopband
frequency in units of π,

4. [b, a]=ellip(N, Rp, As, wn)


This function designs an Nth-order low pass digital elliptic filter with the passband ripple of Rp
decibels and a stopband attenuation of As decibels. It returns the filter coefficients in length N
+1 vectors b and a. The filter order is given by its order equation, and the cutoff frequency wn is
the digital passband frequency in units of π.

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

Figure-7: Direct form I and II Realization

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.

Figure-8: Second Order Cascaded Section

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.

Figure-9: 8th Order IIR Filter

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.

For Exhaustive testing:


• Use for loop to simulate values of input (x) from 0  -8.
• Generate a 50 MHz clock and set the sensitivity of the always block in UUT at positive edge of
the clock.
• In a for loop of test bench, instead of using a manual delay command, give delay until the
positive edge of clock is detected.
Syntax: instead of #10 use @(posedge clk);

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)

Name of Student: …………………………………… Roll No: ………………

Lab #07: Marks distribution


ER1 ER3 ER7 ER9 RR1
Task

Lab #07: Marks obtained


ER1 ER3 ER7 ER9 RR1 Total
Task

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

You might also like