Verilog Review and Fixed Point Arithmetics. Overview

Similar documents
Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

The string of digits in the binary number system represents the quantity

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Computer Science 281 Binary and Hexadecimal Review

Binary Numbering Systems

Introduction to Xilinx System Generator Part II. Evan Everett and Michael Wu ELEC Spring 2013

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Solution for Homework 2

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Lecture 8: Binary Multiplication & Division

Systems I: Computer Organization and Architecture

CS321. Introduction to Numerical Methods

HOMEWORK # 2 SOLUTIO

DNA Data and Program Representation. Alexandre David

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Numerical Matrix Analysis

Floating point package user s guide By David Bishop (dbishop@vhdl.org)

Floating Point Fused Add-Subtract and Fused Dot-Product Units

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Number Representation

Attention: This material is copyright Chris Hecker. All rights reserved.

Monday January 19th 2015 Title: "Transmathematics - a survey of recent results on division by zero" Facilitator: TheNumberNullity / James Anderson, UK

Numbering Systems. InThisAppendix...

FUNDAMENTALS OF MODERN SPECTRAL ANALYSIS. Matthew T. Hunter, Ph.D.

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

HD Radio FM Transmission System Specifications Rev. F August 24, 2011

LMS is a simple but powerful algorithm and can be implemented to take advantage of the Lattice FPGA architecture.

Implementation of Modified Booth Algorithm (Radix 4) and its Comparison with Booth Algorithm (Radix-2)

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

Lecture 2. Binary and Hexadecimal Numbers

Binary Adders: Half Adders and Full Adders

CHAPTER 5 Round-off errors

Digital Hardware Design Decisions and Trade-offs for Software Radio Systems

Department of Electrical and Computer Engineering Ben-Gurion University of the Negev. LAB 1 - Introduction to USRP

CSI 333 Lecture 1 Number Systems

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

AVR223: Digital Filters with AVR. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Lezione 6 Communications Blockset

'Possibilities and Limitations in Software Defined Radio Design.

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

2011, The McGraw-Hill Companies, Inc. Chapter 3

CPEN Digital Logic Design Binary Systems

RN-coding of Numbers: New Insights and Some Applications

RN-Codings: New Insights and Some Applications

Useful Number Systems

Modeling a GPS Receiver Using SystemC

THE EXACT DOT PRODUCT AS BASIC TOOL FOR LONG INTERVAL ARITHMETIC

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

The programming language C. sws1 1

Customizing 16-bit floating point instructions on a NIOS II processor for FPGA image and media processing

DVB-T BER MEASUREMENTS IN THE PRESENCE OF ADJACENT CHANNEL AND CO-CHANNEL ANALOGUE TELEVISION INTERFERENCE

Demonstration of a Software Defined Radio Platform for dynamic spectrum allocation.

Introduction to IQ-demodulation of RF-data

Teaching Convolutional Coding using MATLAB in Communication Systems Course. Abstract

Binary Numbers. Binary Octal Hexadecimal

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Converting Models from Floating Point to Fixed Point for Production Code Generation

Chapter 1: Digital Systems and Binary Numbers

CDMA TECHNOLOGY. Brief Working of CDMA

SDR Architecture. Introduction. Figure 1.1 SDR Forum High Level Functional Model. Contributed by Lee Pucker, Spectrum Signal Processing

Von der Hardware zur Software in FPGAs mit Embedded Prozessoren. Alexander Hahn Senior Field Application Engineer Lattice Semiconductor

The Answer to the 14 Most Frequently Asked Modbus Questions

Non-Data Aided Carrier Offset Compensation for SDR Implementation

AN INTRODUCTION TO DIGITAL MODULATION

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Vector Signal Analyzer FSQ-K70

Number Systems and Radix Conversion

GnuRadio CONTACT INFORMATION: phone: fax: web:

PLL frequency synthesizer

VHDL Test Bench Tutorial

How To Use A Sound Card With A Subsonic Sound Card

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Software Defined Radio

( 214 (represen ed by flipping) (magnitude = -42) = = -42 (flip the bits and add 1)

CS201: Architecture and Assembly Language

DAC Digital To Analog Converter

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

Review of Scientific Notation and Significant Figures

Number and codes in digital systems

A Performance Study of Wireless Broadband Access (WiMAX)

Voice services over Adaptive Multi-user Orthogonal Sub channels An Insight

Let s put together a Manual Processor

Technical Specifications for KD5HIO Software

Transcription:

Verilog Review and Fixed Point Arithmetics CSE4210 Winter 2012 Mokhtar Aboelaze based on slides by Dr. Shoab A. Khan Overview Floating and Fixed Point Arithmetic System Design Flow Requirements and Specifications (R&S) Algorithmic Development in Matlab and Coding Guidelines 2 s Complement Arithmetic Floating Point Format Qn.m format for Fixed Point Arithmetic Addition, Multiplication and Scaling in Qn.m LTI systems and implementation in Qn.m format 1

Floating & Fixed Point Arithmetic Two Types of arithmetic Floating Point Arithmetic After each arithmetic operation numbers are normalized Used where precision and dynamic range are important Most algorithms are developed in FP Ease of coding More Cost (Area, Speed, Power) Fixed Point Arithmetic Place of decimal is fixed Simpler HW, low power, less silicon Converting FP simulation to Fixed-point simulation is time consuming Multiplication doubles the number of bits NxN multiplier produces 2N bits The code is less readable, need to worry about overflow and scaling issues System Design Flow and Fixed Point Arithmetic 2

System Design Flow The requirements and specifications of the application are captured The algorithms are then developed in double precision floating point format Matlab or C/C++ A signal processing system general consists of hybrid target technologies DSPs, FPGAs, ASICs For mapping application developed in double precision is partitioned into hardware & software Most of signal processing applications are mapped on Fixed-point Digital Signal Processors or HW in ASICs or FPGAs The HW and SW components of the application are converted into Fixed Point format for this mapping Requirements & Specifications Gathering R&S is the first step of the system design System components and algorithms are then selected that meet the requirements Example R&S of a UHF Radio are shown Characteristics Output Power Spurious Emission Harmonic Suppression Frequency Stability Reliability Handheld Specifications 2W <60 db >55 db 2ppm or better >10,000 hours MTBF <30 min MTTR 12V DC nickel metal hybrid, nickel cadmium or lithium-ion battery pack 3

R&S of a UHF Radio (cont) Characteristics Frequency Range Specifications 420 MHz to 512 MHz Data rate Channel Modulation FEC Frequency hopping Waveforms Up to 512 kbps multi-channel non-line of sight Multi-path with 15 μs delay spread and 220 km/h relative speed between transmitter and receiver OFDM supporting BPSK, QPSK and QAM Turbo codes, convolution, Reed Solomon > 600 hops/s, frequency hopping on full hopping band Radio works as SDR and should be capable of accepting additional waveforms Algorithm Development and Mapping The R&S related to digital design are forwarded to algorithm developers and system designers Algorithms are coded in behavioral modeling tools like Matlab The Matlab code is then translated into a high level language, for example, C/C++ System is designed based on R&S System usually consists of hybrid technologies consisting of ASICs, DSPs, GPP, and FPGAs Partitioning of the application into HW/SW parts is performed The SW is then developed for the SW part and architectures are designed and implemented for the HW parts Integration and testing is performed throughout the design cycle 4

Guidelines for Matlab Coding Signal processing applications are mostly developed in Matlab As the Matlab code is to be mapped in HW and SW so adhering to coding guidelines is critical The code must be designed to work for processing of data in chunks The code should be structured in distinct components Well defined interfaces in terms of input and output arguments and internal data storages All variables and constants should be defined in data structures User defined configurations in one structure System design constants in another structure Internal states for each block in another structure Initialization in the start of simulation Processing in Chunks % BPSK = 1, QPSK = 2, 8PSK = 3, 16QAM = 4 % All-user defined parameters are set in structure USER_PARAMS USER_PARAMS.MOD_SCH = 2; %select QPSK for current simulation USER_PARAMS.CHUNK_SZ = 256; %set buffer size USER_PARAMS.NO_CHUNKS = 100;% set no of chunks for simulation % generate raw data for simulation raw_data = randint(1, USER_PARAMS.NO_CHUNKS*USER_PARAMS.CHUNK_SZ) % Initialize user defined, system defined parameters and states PARAMS = MOD_Params_Init(USER_PARAMS); STATES = MOD_States_Init(PARAMS); mod_out = []; % Code should be structured to process data on chunk-by-chunk basis for iter = 0:USER_PARAMS.NO_CHUNKS-1 in_data = raw_data (iter*user_params.chunk_sz+1:user_params.chunk_sz*(iter+1)); [out_sig,states]= Modulator(in_data,PARAMS,STATES); mod_out = [mod_out out_sig]; end 5

Fixed Point vs. Floating Point HW Algorithms are developed in floating point format using tools like Matlab Floating point processors and HW are expensive Fixed-point processors and HW are used in embedded systems After algorithms are designed and tested then they are converted into fixed-point implementation The algorithms are ported on Fixed-point processor or application specific hardware Digital Signal Processors 6

Number Representation In a digital design fixed or floating point numbers are represented in binary format Types of Representation one s complement sign magnitude canonic sign digit (CSD) two s complement In digital system design for fixed point implementation the canonic sign digit (CSD), and two s complement are normally used 2 s Complement MSB is the sign bit (has a negative weight) 2 3 2 2 2 1 2 0 1 0 1 1-8 +0 +2 +1= -5 2 3 2 2 2 1 2 0 0 1 1 0 0 +4 +2 +0 = 6 7

Floating Point Format Floating point arithmetic is appropriate for high precision applications Applications that deals with number with wider dynamic range A floating point number is represented as x s = ( 1) 1 m 2 e b s represents sign of the number m is a fraction number >1 and < 2 e is a biased exponent, always positive The bias b is subtracted to get the actual exponent IEEE 754 FP Format (single precision) s e m Sign 0= + 1= - 8 bit True exponent=e-b Bias is 127 23 bit Mantissa is normalized (MSB=1). There is an implied 1 to make it >1 and <2 x = ( 1) s 1. m 2 e 127 8

IEEE 754 FP Format SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM If E=255 and M is nonzero, then V=NaN ("Not a number") If E=255 and M is zero and S is 1, then V=- If E=255 and M is zero and S is 0, then V= If 0<E<255 then V=(-1) S * 2 (E-127) * (1.M) where "1.M" is intended to represent the binary number created by prefixing M with an implicit leading 1 and a binary point. If E=0 and M is nonzero, then V=(-1)**S * 2 ** (-126) * (0.M) These are "unnormalized" values. If E=0 and M is zero and S is 1, then V=-0 If E=0 and M is zero and S is 0, then V=0 Examples 0 00000000 00000000000000000000000 = 0 1 00000000 00000000000000000000000 = -0 0 11111111 00000000000000000000000 = Infinity 1 11111111 00000000000000000000000 = -Infinity 0 11111111 00000100000000000000000 = NaN 1 11111111 00100010001001010101010 = NaN 0 10000000 00000000000000000000000 = +1 * 2**(128-127) * 1.0 = 2 0 10000001 10100000000000000000000 = +1 * 2**(129-127) * 1.101 = 6.5 1 10000001 10100000000000000000000 = -1 * 2**(129-127) * 1.101 = -6.5 0 00000001 00000000000000000000000 = +1 * 2**(1-127) * 1.0 = 2**(-126) 0 00000000 10000000000000000000000 = +1 * 2**(-126) * 0.1 = 2**(-127) 0 00000000 00000000000000000000001 = +1 * 2**(-126) * 0.00000000000000000000001 = 2**(-149) (Smallest positive value) 9

IEEE 754 Double Precision 64 bit number 1 bit for sign 11 bits for exponent 52 bits for mantissa Bias is 1023 FP Addition S0: Append the implied 1 of the mantissa S1: Shift the mantissa from S0 with smaller exponent es to the right by e l e s, where el is the larger of the two exponents S2: For negative operand take two s complement and then add the two mantissas. If the result is negative, again takes two s complement of the result for storing in IEEE format S3: Normalize the sum back to IEEE format by adjusting the mantissa and appropriately changing the value of the exponent e l S4: Round or truncate the resultant mantissa to fit in IEEE format 10

FP Addition -- Example Add these 2 numbers (e=4, m=5, bias=7) 0_1010_00101 = 2 10 7 1.00101=1001.01=9.25 0_1001_00101 = 2 9 7 1.00101=1.00101=4.625 Align 1.00101 2 3 => 1.00101 2 3 1.00101 2 2 => 0.100101 2 3 1.101111 2 3 =1.734375 8=13.875 In FP format 0_1010_10111 = 2 10 7 1.7185=13.75 FP Multiplication S0: Add the two exponents e1 and e2 and subtract the bias once S1: Multiply the mantissas as unsigned numbers to get the product, and XOR the two sign bits to get the sign of the product S2: Normalize the product if required S3: Round or truncate the mantissa 11

Qn.m Format for Fixed-Point Arithmetic Qn.m format is a fixed positional number system for representing floating point numbers A Qn.m format binary number assumes n bits to the left and m bits to the right of the binary point -2 1 2 0. 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 Sign Bit Fraction Bits Fraction Bits Q2.8 Format Example -2 1 2 0. 2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 01 1101 0000 1 + 1/2 1 + 1/2 2 + 1/2 4 = 1.8125 The range of a Q2.8 is -2 (10_000_000) to +1.99609375 (01_1111_1111) In Qn.m n determines the range of the integer, while m determines the precision of the fractional part 12

Fixed Point DSPs Commercially available off the shelf processors usually have16 bits to represent a number In C, a programmer can define 8, 16 or 32 bit numbers as char, short and int/long respectively In case a variable requires different precision than what can be defined in C, the number is defined in higher precision For example an 18-bit number should be defined as a 32-bits integer High precision arithmetic is performed using low precision arithmetic operations 32-bit addition requires two 16-bit addition 32-bit multiplication requires four 16-bit multiplications FP to Fixed Point Comversion Start wit the algorithm (FP) Estimate the range Determine n The fractional part m requires detailed analysis of signal to quantization noise 13

R&S Floating Point algorithm Range estimation SQNR analysis for optimal fractional part determination Fixed point algorithm HW-SW implementation Target system Addition in Q Format Adding two numbers Qn 1.m 1 and Qn 2.m 2 results in Qn.m where N=max(n 1,n 2 )+1, m=max(m 1,m 2 ) Note that the decimal point does not exist in H/W, the designer must align the two number properly 14

Multiplication in Q Format Unsigned by unsigned Straightforward shift and add, no sign extension in general Q(n 1 +n 2 ).(m 1 +m 2 ) 1 1 0 1 = 11.01 in Q2.2 = 3.25 1 0 1 1 = 10.11 in Q2.2 = 2.75 1 1 0 1 1 1 0 1 0 0 0 0 1 1 0 1 1 0 0 0 1 1 1 1 = 1000.1111 in Q4.4 format = 8.9375 Multiplication in Q Format Signed by Unsigned 1 1 0 1 = 11.01 in Q2.2 = 0.75 (signed) Sign extended number 0 1 0 1 = 01.01 in Q2.2 = 1.25 (unsigned 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 1 = 1111.0001 in Q4.4 format = 0.9375 15

Multiplication in Q Format Signed by Unsigned 1 1 0 1 = 11.01 in Q2.2 = 0.75 (signed) 1 1 0 1 = 01.01 in Q2.2 = 3.25 (unsigned 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 1 10 1 1 0 1 1 0 0 1 = 1101.1001 in Q4.4 format = Take 2 s complement 0010.0111 = 2.4375 Multiplication in Q Format Unsigned by Signed 1 0 0 1 = 11.01 in Q2.2 = 2.25 (unsigned) 1 1 0 1 = 01.01 in Q2.2 = 0.75 (signed) 0 0 0 0 1 0 0 1 The 2 s complement of the 0 0 0 0 0 0 0 multiplicand 01001=10111 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 1 0 1 = 1110.0101 in Q4.4 format take 2 s complement it become 0001.1011 = 1.6875 16

Multiplication in Q Format Signed by Signed 1 1 0 1 = 11.01 in Q2.2 = 0.75 (signed) 1 1 0 1 = 1.101 in Q1.3 = 0.375 (signed) 1 1 1 1 1 1 0 1 The 2 s complement of 11.01 since we 0 0 0 0 0 0 0 are multiplying it by 1 1 1 1 0 1 the sign bit 0 0 0 1 1 10 0 0 0 0 1 0 0 1 = 00.01001 in Q2.5 format = 0.28125 Note that there is an extra sign bit so we need 2.5 not 3.5 format 17