1 / 59

Number Representation for DSP processor

Number Representation for DSP processor. Numerical issues and data formats. Fixed point. Fractional number. Floating point. Comparison of formats and dynamic ranges. Numerical Issues and Data Formats. C6000 Numerical Representation. Fixed point arithmetic:

Télécharger la présentation

Number Representation for DSP processor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Number Representation for DSP processor

  2. Numerical issues and data formats. • Fixed point. • Fractional number. • Floating point. • Comparison of formats and dynamic ranges.

  3. Numerical Issues and Data Formats C6000 Numerical Representation Fixed point arithmetic: • 16-bit (integer or fractional). • Signed or unsigned. Floating point arithmetic: • 32-bit single precision. • 64-bit Double precision.

  4. How are numbers represented and processed in DSP processors for implementing DSP algorithms?

  5. How numbers are represented? • A collection of N binary digits (bits) has 2N possible states. • This can be seen from elementary counting theory, which tells us that there are two possibilities for the first bit, two possibilities for the next bit, and so on until the last bit, resulting in 2×2×2… = 2N possibilities or states. • In the most general sense, we can allow these states to represent anything conceivable. • The point is that there is no meaning inherent in a binary word, although most people are tempted to think of them as positive integers. • However, the meaning of an N-bit binary word depends entirely on its interpretation.

  6. Fixed Point number and arithmeticBinary representation of 4-bit signed number

  7. 3 BIT NUMBER IN SIGNED 2’S COMPLEMENT REPRESENTATION

  8. Dynamic range of integer and fraction 4-bit numbers

  9. Dynamic Range • Dynamic range in dB= 20 log10(Max/min) • In fixed point Unsigned integer representation using N-bit range of Max to min number is 2N to 1. • In fixed point signed integer representation using N-bit range of Max to min number is 2N-1 to 1.

  10. In fixed point Unsigned fraction representation using N-bit range of Max to min number is 1-2-Nto 2-N. • In fixed point signed fraction representation using N-bit range of Max to min number is 1-2-N+1to 2-N+1.

  11. Fixed Point Arithmetic - Problems • The following equation is the basis of many DSP algorithms (See Chapter 1): • Two problems arise when using signed and unsigned integers: • Multiplication overflow. • Addition overflow.

  12. 0 0 1 1 0 0 0 0 0 0 0 1 0 1 1 0 Multiplication Overflow • 16-bit x 16-bit = 32-bit • Example: using 4-bit representation • 24 cannot be represented with 4-bits. 3 8 x x 24

  13. 1 1 0 0 0 0 0 0 0 0 0 0 1 Addition Overflow • 32-bit + 32-bit = 33-bit • Example: using 4-bit representation • 16 cannot be represented with 4-bits. 8 8 + + 16

  14. Fixed Point Arithmetic - Solution • The solutions for reducing the overflow problem are: • Saturate the result. • Use double precision result. • Use fractional arithmetic. • Use floating point arithmetic.

  15. 0 0 1 1 1 0 1 0 0 0 0 0 1 1 0 1 0 1 1 0 Solution - Saturate the result • Unsigned numbers: • If A x B  15  result = A x B • If A x B > 15  result = 15 3 8 x 24 Saturated 15

  16. 1 0 1 1 1 0 0 0 1 0 1 0 1 0 0 0 0 1 0 0 Solution - Saturate the result • Signed numbers: • If -8  A x B  7  result = A x B • If A x B > 7  result = 7 • If A x B < -8  result = -8 3 -8 x -24 Saturated -8

  17. Solution - Double precision result • For a 4-bit x 4-bit multiplication hold the result in an 8-bit location. • Problems: • Uses more memory for storing data. • If the result is used in another multiplication the data needs to be represented into single precision format (e.g. prod = prod x sum). • Results need to be scaled down if it is to be sent to an A to D converter.

  18. Solution - Fractional arithmetic • If A and B are fractional then: • A x B < min(A, B) • i.e. The result is less than the operands hence it will never overflow. • Examples: • 0.6 x 0.2 = 0.12 (0.12 < 0.6 and 0.12 < 0.2) • 0.9 x 0.9 = 0.81 (0.81 < 0.9) • 0.1 x 0.1 = 0.01 (0.01 < 0.1)

  19. a= 0 1 1 0 = 0.5 + 0.25 = 0.75 b= 1 1 1 0 = -1 + 0.5 + 0.25 = -0.25 0 0 0 0 0 1 1 0 . 0 1 1 0 . . 1 0 1 0 . . . Sign extension 1 1 1 1 0 1 0 0 1 1 1 0 Fractional numbers - Sign Extension x • To keep the same resolution as the operands we need to select these 4-bits:

  20. 1 1 1 1 0 1 0 0 Fractional numbers - Sign Extension a= 0 1 1 0 = 0.5 + 0.25 = 0.75 • The way to do it is to shift left by one bit and store upper 4-bits or right shift by three and store the lower 4-bits: b= 1 1 1 0 x = -1 + 0.5 + 0.25 = -0.25 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 . 0 0 0 1 1 0 . . Sign extension bits 1 1 0 1 0 . . . Sign extension 1 1 1 0

  21. Although using 2's complement integers we can implement both addition and subtraction by usual binary addition (with special care for the sign bit), the integers are not convenient to handle to implement DSP algorithms. • For example, if we multiply two 8-bit words together, we need 16 bits to store the result.

  22. The number of required word length increases without bound as we multiply numbers together more. • Although not impossible, it is complicated to handle this increase in word-length using integer arithmetic. • The problem can be easily handled by using numbers between -1 and 1, instead of integers, because the product of two numbers in [-1,1] are always in the same range.

  23. In the 2's complement fractional representation, an N bit binary word can represent 2N equally space numbers from • For example, we interpret an 8-bit binary word b7 b6b5b4b3b2b1b0 • as a fractional number • This representation is called Q-format.

  24. Integer Vs Fractional Number • Different notation are used to represent different binary formats. • The Qm.n represent are most widely used • In Qm.n representation m bit representation integer portion and n bit represent fraction number • Eg Q15.0 and Q0.15 • If N is total number of bits then N=m+n+1.

  25. Number range is -2^m to 2^m – 2^-n • Its resolution is 2^-n • For eg Q14.1 representation • Its range is • [-2^14, 2^14 – 2^-1] = [-16384.0, +16383.5] = So in hex [0x8000, 0x8001 … 0xFFFF, 0x0000, 0x0001 … 0x7FFE, 0x7FFF] resolution is 2^-1=0.5

  26. Conversion • To convert a number from floating point to Qm.n format: • 1.Multiply the floating point number by 2n • 2.Round to the nearest integer

  27. Conversion • To convert a number from Qm.n format to floating point • 1.Convert the number directly to floating point • 2.Divide by 2^n

  28. In C6211, it is easiest to handle Q-15 numbers represented by each 16 bit binary word, because the multiplication of two Q-15 numbers results in a Q-30 number that can still be stored in a 32-bit wide register of C6211. • The programmer needs to keep track of the implied binary point when manipulating Q-format numbers.

  29. CPU MPY A3,A4,A6 NOP Q15 s. x x x x x x x x x x x x x x x x Q15 Q15 s. s. y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y Q30 s s. z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z Store to Data Memory SHR A6,15,A6 STH A6,*A7 15-bit * 15-bit Multiplication

  30. Assembly language implementation • When A0 and A1 contain two 16-bit numbers in the Q-15 format, we can perform the • multiplications using MPY followed by a right shift. • 1 MPY .M1 A0,A1,A2 • 2 NOP • 3 SHR .S1 A2,15,A2 ;lower 16 bit contains result • in Q-15 format

  31. C language implementation • Let's suppose we have two 16-bit numbers in Q-15 format, stored in variable x and y as follows: • short x = 0x0011; /* 0.000518799 in decimal */ • short y = 0xfe12; /* -0.015075684 in decimal */ • short z; /* variable to store x*y */ • The product of x and y can be computed and stored in Q-15 format as follows: • z = (x * y) > > 15; • The result of x*y is a 32-bit word with 2 sign bits. Right shifting it by 15 bits ignores the last 15 bits, and storing the shifted result in z that is a short variable (16 bit) removes the extended sign bit by taking only lower 16 bits.

  32. However, care must be taken when adding binary numbers. • Because each Q-15 number can represent numbers in the range [-1,1−215] , if the result of summing two Q-15 numbers is not in this range, we cannot represent the result in the Q-15 format. • When this happens, we say an overflow has occurred.

  33. Unless carefully handled, the overflow makes the result incorrect. • Therefore, it is really important to prevent overflows from occurring when implementing DSP algorithms. • One way of avoiding overflow is to scale all the numbers down by a constant factor, effectively making all the numbers very small, so that any summation would give results in the [-1,1) range. • This scaling is necessary and it is important to figure out how much scaling is necessary to avoid overflow. • Because scaling results in loss of effective number of digits, increasing quantization errors, we usually need to find the minimum amount of scaling to prevent overflow.

  34. Most Fixed-Point DSP processor use two’s complement fractional numbers in different Q format. However assembler only recognize integer value. • So we have to keep track of binary point when considering fractional number in assembly program.

  35. Steps of converting fractional number into Q-format into an integer that can be recognized by the assembler • 1. Normalize the fractional number to the range determined by the desired Q-format. • 2. Multiply the Normalized fractional by 2^n, where n is the total number of fractional bits. • 3. Round the product to the nearest integer.

  36. ‘C6000 C Data Types Type Size Representation char, signed char 8 bits ASCII unsigned char 8 bits ASCII short 16 bits 2’s complement unsigned short 16 bits binary int, signed int 32 bits 2s complement unsigned int 32 bits binary long, signed long 40 bits 2’s complement unsigned long 40 bits binary enum 32 bits 2’s complement float 32 bits IEEE 32-bit double 64 bits IEEE 64-bit long double 64 bits IEEE 64-bit pointers 32 bits binary

  37. Exponential Notation • The following are equivalent representations of 1,234 123,400.0 x 10-2 12,340.0 x 10-1 1,234.0 x 100 123.4 x 101 12.34 x 102 1.234 x 103 0.1234 x 104 The representations differ in that the decimal place – the “point” -- “floats” to the left or right (with the appropriate adjustment in the exponent). p. 122

  38. Exponent Sign ofexponent Mantissa Sign ofmantissa Location ofdecimal point Base p. 123 Parts of a Floating Point Number -0.9876 x 10-3

  39. IEEE 754 Standard • Most common standard for representing floating point numbers • Single precision: 32 bits, consisting of... • Sign bit (1 bit) • Exponent (8 bits) • Mantissa (23 bits) • Double precision: 64 bits, consisting of… • Sign bit (1 bit) • Exponent (11 bits) • Mantissa (52 bits) p. 133

  40. Mantissa (23 bits) Exponent (8 bits) Sign of mantissa (1 bit) Single Precision Format 32 bits

  41. Normalization • The mantissa is normalized • Has an implied decimal place on left • Has an implied “1” on left of the decimal place • E.g., • Mantissa  • Represents… 10100000000000000000000 1.1012 = 1.62510

  42. Excess Notation • To include +ve and –ve exponents, “excess” notation is used • Single precision: excess 127 • Double precision: excess 1023 • The value of the exponent stored is larger than the actual exponent • E.g., excess 127, • Exponent  • Represents… 10000111 135 – 127 = 8

  43. 1.112 130 – 127 = 3 0 = positive mantissa +1.112 x 23 = 1110.02 = 14.010 Example • Single precision 0 10000010 11000000000000000000000

  44. Hexadecimal • It is convenient and common to represent the original floating point number in hexadecimal • The preceding example… 0 10000010 11000000000000000000000 4 1 6 0 0 0 0 0

  45. Converting from Floating Point • E.g., What decimal value is represented by the following 32-bit floating point number? C17B000016

  46. S E M 1 = negative 0 = positive • Step 1 • Express in binary and find S, E, and M C17B000016 = 1 10000010 111101100000000000000002

  47. Step 2 • Find “real” exponent, n • n = E – 127 = 100000102 – 127 = 130 – 127 = 3

  48. Step 3 • Put S, M, and n together to form binary result • (Don’t forget the implied “1.” on the left of the mantissa.) -1.11110112 x 2n= -1.11110112 x 23 = -1111.10112

  49. Step 4 • Express result in decimal -1111.10112 -15 2-1 = 0.5 2-3 = 0.125 2-4 = 0.0625 0.6875 Answer: -15.6875

More Related