In a given rectangular coordinate system, points whose coordinates are all integers are called whole points;The group composed of all whole points is called spatial grid.The operations in the spatial grid are calledFixed-point operation。In addition to fixed-point operations, of course, floating point operations.
Fixed point number: Generally speaking, the number with a fixed decimal point.Taking RMB as an example, we often talk about 123.45¥,789。34 ¥ and so on. By default, there are two decimal places after the decimal point, namely, angle and minute.If the decimal point is in front of the most significant digit, such a number is called the fixed point number of pure decimal, such as 0.12345,0。78934, etc.If the decimal point is behind the least significant digit, such number is called the fixed point number of pure integer, such as 1234578934.
A method of representing numbers in which the decimal point is fixed.When representing a number, the decimal point is usually fixed before the highest position of the number, so that the absolute value of the number (i.e. mantissa or digit) is less than 1, which is in the form of number sign and mantissa.For integer numbers, the decimal point is fixed at the lowest position of the number.The number expressed by fixed-point representation is called fixed-point number.[1]
Floating point number: Generally speaking, a number with an unfixed decimal point.The easier way to understand it is to consider the followingScientific notation, take our numbers above for example, 123.45, which can be written in the following forms: 12.345x1011;2345x1020;12345x103 In order to represent a number, the position of the decimal point can change, that is, the decimal point is not fixed.
In order to ensure the speed of signal calculation, assembly language and fixed-point number are mostly used in the language of data medium, small computers and microcomputers when they are used for simulation calculation or as special control computers.When calculating with fixed point numbers, it is required that all quantities involved in the operation, whether the initial value or the intermediate result, or the value of the final result, must be strictly limited to the (- 1,+1) interval, or overflow will occur during the operation.
Fixed point operation of DSP chip
Announce
edit
At a fixed pointDSP chipMedium, usingNumber of fixed pointsFor numerical operation, the operands are generally expressed as integer numbers.The maximum representation range of an integer depends onDSP chipThe given word length is generally 16 bits or 24 bits.Obviously, the longer the word length is, the larger the range of numbers can be expressed,accuracyThe higher.Unless otherwise specified, this book takes 16 bit word length as an example.The number of DSP chips is 2ComplementFormal representation.Each 16 digit number uses a sign bit to represent the positive and negative of the number, 0 means the value is positive, and 1 means the value is negative.The remaining 15 bits represent the size of the value.
therefore, binary number001000000000011b=8195 Binary number 1111111111111100b=- 4 pairsDSP chipIn other words, the number participating in numerical operation is a 16 bit integer number.But in many cases, the number in the process of mathematical operation is not necessarily an integer.Then, how does the DSP chip handledecimalWhat about?It should be said that the DSP chip itself is powerless.Does that mean that the DSP chip can't handle all kinds ofdecimalWhat about?Of course not.The key is that the programmer determines a numberdecimal pointWhich of the 16 bits is it.This is the scaling of numbers.By setting different positions of the decimal point in 16 digits, different sizes andaccuracyIs a decimal of.The fixed number is marked with Q representation and S representation.Table 3.1 lists 16 Q and S representations of a 16 digit number and what they can representdecimal systemRange of values.It can be seen from Table 3.1 that for the same 16 digit number, if the decimal point is set at different positions, the number it represents will be different.For example: 16BaseThe number 2000H=8192. Q0 is used to represent the hexadecimal number 2000H=0.25, and Q15 is used to represent it. But for DSP chips, the processing method is completely the same.It can also be seen from Table 3.1 that different Q not only has different ranges, but alsoaccuracyNot the same.The larger the Q, the smaller the numerical range, butaccuracyHigher;On the contrary, the smaller the Q, the larger the numerical range, but the lower the accuracy.For example, the value range of Q0 is - 32768 to+32767accuracyIs 1, while the value range of Q15 is - 1 to 0.9999695, and the precision is 1/32768=0.00003051.Therefore, forNumber of fixed pointsFor, the range of values isaccuracyIt is a pair of contradictions. If a variable wants to represent a relatively large numerical range, it must sacrifice precision;If you want to improve the accuracy, the number representation range will be reduced accordingly.At the actual fixed pointalgorithmIn order to achieve the best performance, this must be fully considered.Floating point numberAndNumber of fixed pointsThe conversion relationship of can be expressed as:Floating point number(x) Convert toNumber of fixed points(): fixed-point number () is converted to floating point number (x): for example, floating point number x=0.5, calibration Q=15, which means rounding down.On the contrary, aNumber of fixed points16384, whichFloating point number16384 × 2-15=16384/32768=0.5.
From floating point to fixed point
Announce
edit
When writing DSP simulation algorithm, for convenience, we usually usehigh-level language(such as C language).The variables used in the program generally include both integer numbers andFloating point number。As shown in Example 3.1, the variable i in the program is an integer, while pi isFloating point numberHamwindow is a floating point array.
Example 3.1 256 point Hamming window calculation
inti;
floatpi=3.14159;
floathamwindow[256];
for(i=0;iQy,addition/subtractionThe calibration value of result z is Qz, then
Since the Q value of z is 13, the fixed point value z=29491 isfloating-pointThe value z=29491/8192=3.6.
Example 3.3 Fixed point subtraction
Let x=3.0, y=3.1, then the floating point operation result is z=x-y=3.0-3.1=- 0.1;
Qx=13, Qy=13, Qz=15, then the fixed-point subtraction is:
x=24576;y=25295;
temp=25395;
temp=x-temp=24576-25395=-819;
Because QxQy,additionThe calibration value of z is Qz, so the fixed-point addition is:
intx,y;
longtemp,z;
Temp=y>(Qx Qz), if Qx ≥ Qz
Z=temp32767, so
Qx=1, Qy=0, Qz=0, then the fixed pointadditionFor:
x=30000;y=20000;
temp=20000>1=35000;
Since the Q value of z is 0, the fixed point value z=35000 is a floating point value, where z is a long integer.
When addition or the result of addition exceeds the 16 bit representation range, if the programmer can understand this situation in advance and needs to ensure the operationaccuracyMust maintain 32-bit results.If 16digitIf the number of bits exceeds 16, an overflow occurs.If proper measures are not taken, the data overflow will lead to serious deterioration of the calculation accuracy.General fixed pointDSP chipBoth are equipped with overflow protection function. When the overflow protection function is effective, once overflow occurs, the result of accumulator ACC is the maximum saturation value(OverflowIs 7FFFH,Underflow8001H) to prevent overflowaccuracyThe purpose of serious deterioration.
3.2.2 C language fixed-point simulation of multiplication
set upfloating-pointThe expression of multiplication is:
floatx,y,z;
z=xy;
Assuming that the scaling value of x after statistics is Qx, the scaling value of y is Qy, and the scaling value of product z is Qz, then
z=xyÞ
=Þ
=
So the multiplication of fixed-point representation is:
intx,y,z;
longtemp;
temp=(long)x;
z=(temp×y)>>(Qx+Qy-Qz);
Example 3.5 Fixed point multiplication
Let x=18.4, y=36.8, thenfloating-pointThe operation value is z=18.4 × 36.8=677.12;
According to the previous section, Qx=10, Qy=9, Qz=5, so
x=18841;y=18841;
temp=18841L;
z=(18841L*18841)>>(10+9-5)=354983281L>>14=21666;
Since the scaling value of z is 5, the fixed point z=21666 is the floating point z=21666/32=677.08.
Set floating pointdivisionThe expression of the operation is:
floatx,y,z;
z=x/y;
Assume that after statisticsDividendThe scaling value of x is Qx, the scaling value of divisor y is Qy, and the scaling value of quotient z is Qz, then