Documente Academic
Documente Profesional
Documente Cultură
Remarks: …………………………………………………
Instructor’s Signature:………….………………….
Objectives
1. Gain familiarity with the number representation method i.e. fixed point and floating point.
2. Learn how to convert FIR 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.
Example-1
Number Represented in (Q4.4) Format = 8’b01110110
Real Number for Above Format= 4 + 2 + 1 + 0.25 + 0.125 = 7.375
In many A/D converters and processors, the real numbers are scaled so that the fixed point
representation is in the (−1, 1) range. This has the advantage that the multiplication of two
fractions is always a fraction and, as such, there is no overflow. Hence we will consider the
following representation:
Example-2
Represent the number 𝑥̂ = -10.4375 using fraction only arrangement.
Solution:
Choose A = 24 = 16 and B=9
𝑥̂ = -10.4375 = 16 (1.101001110)
3
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*2ˆB)/2ˆB; implements the
desired operation.
Example-3
= 8’b01110110 (Q4.4)
= 4 + 2 + 1 + 0.25 + 0.125 = 7.375
Truncate it to Q4.2 results
=6’b011101 = 7.25
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*2ˆB)/2ˆB; implements the
desired operation.
Example-4
The fractional part requires detail analysis of signal to quantization noise analysis (SQNR).
4
Figure-1: Floating Point to Fixed Point Conversion
MATLAB Implementation
Shift left m fractional bits to the integer part and truncate or round the results. In MATLAB, the
conversion is done as,
num_fixed = fix(num_float * 2m) or
num_fixed = round(num_float * 2m)
Also saturate the result if number is greater than the maximum positive number or less than
the minimum negative number.
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
frequencies and not others in order to suppress interfering signals and reduce background
noise.
5
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 x̂(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 (i.e., very large numbers or very small numbers). 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.
For a FIR filter of order N, each value of the output sequence is a weighted sum of the most
recent input values:
6
Figure-3: 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.
• 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.
7
Design Techniques for FIR Filter
There are three design techniques for FIR filter design, namely
1) Window design,
2) Frequency Sampling Design
3) Optimal equiripple Design techniques for linear phase FIR filters. (Using Park McClellan
Algorithm with Remez Exchange Polynomial)
The SP toolbox provides a function called fir2, which combines the frequency-sampling
technique with the window technique to design arbitrary-shaped magnitude response FIR
filters. After computing the filter impulse response using the naive design method, fir2 then
applies a selected window to minimize ripples near the band-edge frequencies. This function’s
syntax also has several forms, including:
• h = fir2 (N,f,m) designs an Nth-order (N = M−1) lowpass FIR filter and returns the impulse
response in vector h. The desired magnitude response of the filter is supplied in vectors f and
m, which must be of the same length. The vector f contains normalized frequencies in the range
from 0 to 1, where 1 corresponds to π rad/sample. The first value of f must be 0 and the last
value 1. The vector m, contains the samples of the desired magnitude response at the values
specified in f. The desired frequency response is then interpolated onto a dense, evenly spaced
grid of length 512. Thus this syntax corresponds to the naïve design method.
• h = fir2 (N, f, m, window) uses the vector window of length N+1 obtained from one of the
specified MATLAB window functions. The default window function used is the Hamming
window.
• h = fir2 (N, f, m, npt) or h = fir2 (N, f, m, npt, window) specifies the number of points npt for
the grid onto which fir2 interpolates the frequency response. The default npt value is 512.
8
Lab Task:
You need to implement the given fir filter as shown in fig-3 in Verilog and write a test bench for
exhaustive testing. Follow the given guidelines properly to implement task successfully.
The required parameters for the coefficients and input are given in table:
SIGNED
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 and fill table 2 with your calculated values.
3) Write a Verilog code and a appropriate test bench for the above filter accordingly.
4) Verify your simulations with the help of calculations performed.
Calculated Results:
Filter Parameters Floating Point Fixed Point
a 0.0625
b -0.375
c 2.5
x -8.0
a_r
b_r
9
c_r
ab
y[n]
x -4.0
a_r
b_r
c_r
ab
y[n]
Table 2: Calculated Results
Expected Results:
10
Labs Rubrics
Experiment # 06
Implementation of Finite Impulse Response (FIR) Filter using Fixed
Point Arithmetic (Qn.m) and Stimulus Writing for Exhaustive Testing
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
11
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
12