C language fixed-point simulation of multiplication operation in DSP programming[Copy link]
Suppose the expression of floating-point multiplication operation is: float x, y, z; z=xy; Assume that after statistics, the calibration value of x is Qx, the calibration value of y is Qy, and the calibration value of the product z is Qz, then z=xy zq*2-Qx=xq*yq*2-(Qx+Qy) zq=(xqyq)2Qz-(Qx+Qy) So the multiplication expressed in fixed-point form is: int x, y, z; long temp; temp=(long)x; z=(temp*y)>>(Qx+Qy-Qz); Example 1.5 Fixed-point multiplication. Assume x=18.4, y=36.8, then the floating-point operation value is =18.4*36.8=677.12; According to the previous section, we have Qx=10, Qy=9, Qz=5, so x=18841; y=18841; temp=18841L; z=(18841L*18841)>>(10+9-5)=354983281L>>14=21666; Because the calibration value of z is 5, the fixed-point z=21666, that is, the floating-point z=21666/32=677.08. 2.3 C language fixed-point simulation of division operation Assume that the expression of floating-point division operation is: float x, y, z; z=x/y; Assume that after statistics, the calibration value of the dividend x is Qx, the calibration value of the divisor y is Qy, and the calibration value of the quotient z is Qz, then z=x/y zq*2-Qz=(xq*2-Qx)/(yq*2-Qy) zq=(xq*2(Qz-Qx+Qy))/yq So the fixed-point representation of division is: int x, y, z; long temp; temp=(long)x; z=(temp<<(Qz-Qx+Qy))/y; Example 1.6 Fixed-point division. Assume x=18.4, y=36.8, the floating point value is z=x/y=18.4/36.8=0.5; According to the previous section, we have Qx=10, Qy=9, Qz=15; so z=18841, y=18841; temp=(long)18841; z=(18841L<<(15-10+9)/18841=3O8690944L/18841=16384; Because the calibration value of the quotient z is 15, the fixed point z=16384, that is, the floating point z=16384/215=0.5.