Three cases of DSP fixed-point multiplication[Copy link]
When two fixed-point numbers are multiplied, there are three cases: 1. Decimal multiplication 2. Decimal multiplication Example 1.9 Q15*Q15=Q30 0.5*0.5=0.25 0.1000000000000000; Q15*Q15=Q30 0.5*0.5=0.25 0.10000000000000000; Q15*Q15=Q30 0.5*0.5=0.25 0.10000000000000000; Q15*Q15=Q30 0.5*0.5=0.25 0.100000000000000000; Q15*Q15=Q30 0.5*0.5=0.25 0.5*0.5=0.25 0.1000000000000000; Q15 -------------------------------------------- 00.0100000000000000000000000000000=0.25; Q30 The multiplication of two Q15 decimals results in a Q30 decimal, which has two sign bits. In general, the full-precision number obtained after multiplication does not need to be retained in full, but only 16-bit single-precision numbers need to be retained. Since the high 16 bits after multiplication are less than 15 bits of small data, in order to achieve 15-bit accuracy, the product can be shifted left by one bit. The following is the TMS320C25 program for the above multiplication: LT OP1; OP1=4000H(0.5/Q15) MPY OP2; oP2=4000H(0.5/Ql5) PAC SACH ANS,1;ANS=2000H(0.25/Q15) 2. Multiply integers by integers Example 1.10 Q0*Q0=Q0 17*(-5)=-85 [color=#4f4 f4f]0000000000010001=l7 *111111111111011=-5 --------------------------------------------- 1111111111111111111111110101011=-85 3. Mixed representation In many cases, in order to satisfy the dynamic range of the value and ensure a certain degree of accuracy during the calculation process, it is necessary to use a representation between Q0 and Q15. For example, the value 1.2345 cannot be represented by Q15, and if it is represented by Q0, the closest number is 1, and the accuracy cannot be guaranteed. Therefore, the best representation for the number 1.2345 is Q14. Example 1.11 1.5*0.75= 1.125 01.10000000000000=1.5; Q14 [font =-apple-system,]*00.11000000000000=0.75;Q14 ------------------------------------------ 0001.00100000000000000000000000000=1.125 Q28 The maximum value of Q14 is no greater than 2, so the product of two Q14 numbers is no greater than 4. In general, if one number has i integer digits and j decimal digits, and the other number has m integer digits and n decimal digits, then the product of the two numbers is (i+m) integer digits and (j+n) decimal digits. The highest possible 16-bit precision of this product is (i+m) integer digits and (15-i-m) decimal digits. However, if the dynamic range of the number is known in advance, the precision of the number can be increased. For example, if the programmer knows that the product above will not be greater than 1.8, the product can be expressed as Q14 instead of the theoretical best case Q13. The TMS320C25 program of Example 3.11 is as follows: LT OP1; OP1 = 6000H(1.5/Ql4)MPY OP2; OP2 = 3000H(0.75/Q14)PACSACH ANS,1;ANS=2400H(1.125/Q13)In the above method, the multiplication result is truncated for accuracy, and the error in the result is equivalent to subtracting one LSB (least significant bit). The following simple rounding method can reduce the error by one-half. LT OP1 MPY OP2 PAC ADD ONE,14(round up) SACH ANS,1 The above program shows that no matter whether ANS is positive or negative, the error generated is 1/2 LSB, and the value of storage unit ONE is 1.