1531 views|0 replies

2015

Posts

0

Resources
The OP
 

About DSP data calibration [Copy link]

, 254, 242)]-DSP fixed-point arithmetic 1 Number scaling In fixed-point DSP chips, fixed-point numbers are used for numerical calculations, and their operands are generally represented by integers. The maximum representation range of an integer depends on the word length given by the DSP chip, which is generally 16 bits or 24 bits. Obviously, the longer the word length, the larger the range of numbers that can be represented and the higher the precision. Unless otherwise specified, this book uses 16-bit word length as an example. The numbers of DSP chips are represented in 2's complement form. Each 16-bit number uses a sign bit to indicate the positive or negative of the number, 0 indicates a positive value, and 1 indicates a negative value. The remaining 15 bits indicate the size of the value. Therefore, the binary number 0010000000000011b=8195 The binary number 111111111111100b= -4 sans-serif]For DSP chips, the numbers involved in numerical calculations are 16-bit integers. But in many cases, the numbers in mathematical calculations are not necessarily integers. So, how do DSP chips handle decimals? It should be said that DSP chips themselves are powerless. Does that mean that DSP chips cannot handle various decimals? Of course not. The key is for the programmer to determine which position of the decimal point of a number is located in the 16-bit number. This is the calibration of the number. By setting the decimal point in different positions in the 16-bit number, decimals of different sizes and different precisions can be represented. There are two types of number calibration: Q representation and S representation. Table 1.1 lists the 16 Q representations and S representations of a 16-bit number and the decimal value ranges they can represent. From Table 1.1, we can see that for the same 16-digit number, if the decimal point is set in a different position, the number it represents will be different. For example, the hexadecimal number 2000H=8192, represented by Q0, and the hexadecimal number 2000H=0.25, represented by Q15. But for DSP chips, the processing method is exactly the same. It can also be seen from Table 1.1 that the numbers represented by different Qs have different ranges and precisions. The larger the Q, the smaller the numerical range, but the higher the precision; on the contrary, the smaller the Q, the larger the numerical range, but the lower the precision. For example, the numerical range of Q0 is -32768 to +32767, and its precision is 1, while the numerical range of Q15 is -1 to 0.9999695, and its precision is 1/32768=0.00003051. Therefore, for fixed-point numbers, numerical range and precision are a contradiction. If a variable wants to represent a relatively large numerical range, it must sacrifice precision; and if the precision is improved, the numerical range will be reduced accordingly. In actual fixed-point algorithms, in order to achieve the best performance, this point must be fully taken into account. The conversion relationship between floating-point numbers and fixed-point numbers can be expressed as: The conversion of floating-point numbers (x) to fixed-point numbers (xq) is: xq=(int)x* 2Q For example, if the floating point number x=0.5 and the calibration Q=15, then the fixed point number xq=L0.5*32768J=16384, where LJ means rounding down. Conversely, a fixed point number 16384 represented by Q=15 has a floating point number of 163*2-15=16384/32768=0.5. When converting a floating-point number to a fixed-point number, 0.5 can be added before rounding to reduce truncation error. Table 1.1 Q representation, S representation and value range Q representation S representation Decimal representation range Q15 S0.15 -1≤x≤0.9999695 Q14 S1.14 -2≤x≤1.9999390 Q13 S2.13 -4≤x≤3.9998779 Q12 S3.12 -8≤x≤7.9997559 Q11 S4.11 -16≤x≤15.9995117 [color=#00 0]Q10 S5.10 -32≤x≤31.9990234 Q9 S6.9 -64≤x≤63.9980469 Q8 S7.8 -128≤x≤127.9960938 Q7 S8.7 -256≤x≤255.9921875 Q6 S9.6 -512≤x≤511.9804375 Q5 S10 .5 -1024≤x≤1023.96875 Q4 S11.4 -2048≤x≤2047.9375 Q3 S12.3 -4096≤x≤4095.875 Q2 S13.2 -8192≤x≤8191.75 Q1 S14.1 Q0 S15.0 -32768≤x≤32767 2 High-level language: from floating point to fixed point When we write DSP simulation algorithms, for convenience, we usually use high-level languages (such as C) to write simulation programs. The variables used in the program generally include both integers and floating-point numbers. For example, in Example 1.1, the variable i is an integer, while pi is a floating-point number, and hamwindow is a floating-point array. Example 1.1 256-point Hamming window calculation int i;+ float pi= 3.14l59; float hamwindow[256 ]; for(i=0;i<256;i++) hamwindow=0.54-0.46*cos (2.0*pi*i/255); If we want to implement the above program with a fixed-point DSP chip, we need to rewrite the above program into an assembly language program for the DSP chip. In order to facilitate DSP program debugging and simulate the algorithm performance when implementing fixed-point DSP, Before writing DSP assembly program, it is generally necessary to rewrite high-level language floating-point arithmetic into high-level language fixed-point arithmetic. Next, we discuss the fixed-point implementation method of basic arithmetic operations. 2.1 Addition/subtraction in C Language fixed-point simulation Set floating point The expression for addition operation is: float x,y,z; z=x+y; color=#000]The most important point when converting floating point addition/subtraction to fixed point addition/subtraction is to ensure that Scaling of two operands temp=x+temp; z=temp>>(Qx-Qz), if Qx>=Qz [color=# 000]z=temp<<(Qz-Qx), if Qx<=Qz[/backcolor Example 1.4 Fixed-point addition with a result exceeding 16 bits /backcolor] Let x=15000, y=20000, then the floating point value is z=x+y=35000, obviously z>32767, so[ /backcolor] Qx=1,Qy=0,Qz=0, The fixed-point addition is: x= 30000;y=20000; temp=20000<<1=40000;[/ color] temp=temp+x=40000+30000=70000;[ /backcolor] z=70000L>>1=35000;[/font ] [font=Verdana, Arial, Helvetica,[sans-serif]Because 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 the result of addition or addition exceeds the 16-bit representation range, if the programmer is aware of this situation in advance and needs to maintain the calculation accuracy, the 32-bit result must be maintained. If the program is operated according to 16-bit numbers, exceeding 16 bits is actually an overflow. If appropriate measures are not taken, data overflow will cause a serious deterioration in calculation accuracy. General fixed-point DSP chips do not have overflow protection function. When the overflow protection function is effective, once an overflow occurs, the result of the accumulator ACC is the maximum saturation value (overflow is 7FFFH, underflow is 8001H), thereby preventing overflow from causing a serious deterioration in accuracy. 2.2 Fixed-point simulation of multiplication in C language Suppose the expression of floating-point multiplication is: float x,y,z; z=xy; Suppose 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; , Helvetica, sans-serif]zq*2-Qx=xq*yq*2-(Qx+Qy) zq=(xqyq)2Qz-(Qx+Qy) So the fixed-point representation of multiplication is: sans-serif]int x, y, z; long temp; temp=(long)x; z=(temp*y)>>(Qx+Qy-Qz);[ /backcolor] Example 1.5 Fixed-point multiplication. Suppose x=18.4, y=36.8, then the floating-point value is =18.4*36.8=677.12; According to the previous section, Qx=10, Qy=9, Qz=5, so x=18841;y=18841; temp=18841L; [backcolor= rgb(254, 254, 242)]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 Fixed-point simulation of division in C language Suppose the expression of floating-point division is: float x,y,z; z=x/y; Suppose 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=(xq*2(Qz-Qx+Qy))/yq int x, y, z; long temp; temp=(long)x; z=(temp<<(Qz-Qx+Qy))/y; Example 1.6 Fixed-point division. Suppose x=18.4, y=36.8, and 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 we have sans-serif]z=18841,y=18841; temp=(long)18841; [back color=rgb(254, 254, 242)]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. 2.4 Determination of the Q value of the program variable sans-serif]In the examples introduced in the previous sections, since the values of x, y, and z are all known, the Q value is easy to determine when changing from floating point to fixed point. In actual DSP applications, variables are involved in the calculation in the program, so how to determine the Q value of the variable in the floating point program? From the previous analysis, we can know that determining the Q value of a variable is actually determining the dynamic range of the variable. Once the dynamic range is determined, the Q value is also determined. Let the maximum absolute value of the variable be |max|. Note that |max| must be less than or equal to 32767. Take an integer n such that 2n-1<|max|<2n Then 2-Q=2-15*2n=2-(15-n) Q=15-n Q=15-n For example, the value of a variable is between -1 and +1, that is, |max|<1, so n=0, Q=15-n=15. Since we can determine the Q value by determining the |max| of a variable, how do we determine the |max| of a variable? Generally speaking, there are two methods to determine the |max| of a variable. One is theoretical analysis, and the other is statistical analysis. 1. Theoretical Analysis The dynamic range of some variables can be determined through theoretical analysis. For example: (1) Trigonometric function. y=sin(x) or y=cos(x). From the knowledge of trigonometric functions, we know that |y|<=1. (2) Hamming window. y(n)=0.54-0.46cos[nπn/(N-1)], 0<=n<=N-1. Because -1<=cos[2πn/(N-1)]<=1, so 0.08<=y(n)<=1.0. (3) FIR convolution. y(n)=∑h(k)x(nk), let ∑|h(k)|=1.0, and x(n) is the 12-bit quantized value of the analog signal, that is, |x(n)|<=211, then |y(n)|<=211. (4)It has been theoretically proved that in the programming of autocorrelation linear prediction coding (LPC), the reflection coefficient ki satisfies the following inequality: |ki|<1.0, i=1, 2, ..., p, where p is the order of LPC. 2. Statistical analysis method For variables whose range cannot be determined theoretically, statistical analysis is generally used to determine their dynamic range. The so-called statistical analysis is to use enough input signal samples to determine the dynamic range of the variables in the program. Here, the input signal must have a certain number on the one hand, and on the other hand, it must involve various situations as much as possible. For example, in speech signal analysis, statistical analysis must collect enough speech signal samples, and the collected speech samples should include various situations as much as possible. Such as the volume, the type of sound (male voice, female voice, etc.). Only in this way can the statistical results be typical. Of course, statistical analysis cannot cover all possible situations. Therefore, some protection measures can be taken for the statistical results during program design, such as appropriately sacrificing some accuracy, taking the Q value slightly larger than the statistical value, and using the overflow protection function provided by the DSP chip. 2.5 Example of C program for floating point to fixed point conversion In this section, we use an example to illustrate the method of converting C program from floating point to fixed point. This is a C language program for low-pass filtering of speech signals (0.3~3.4kHz). The cutoff frequency of the low-pass filter is 800Hz, and the filter uses a 19-point finite impulse response FIR filter. The sampling frequency of the speech signal is 8kHz, and each speech sample value is stored in the insp.dat file as a 16-bit integer. Example 1.7 Speech signal 800Hz 19-point FIR low-pass filter C language floating-point program. #i nclude const int length=180/*The voice frame length is 180 points=22.5ms@8kHz sampling*/ void filter(int xin[], int xout[], int n, float h[]); /*Filter subroutine description*/ /*19-point filter coefficients*/ static float h[19]= {0.01218354,-0.009012882,-0.02881839,-0.04743239,-0.04584568, -0.008692503, 0.06446265, 0.1544655, 0.2289794, 0.257883, 0.2289794,0.1544655,0.06446265,-0.008692503,-0.04584568, -0.04743239,-0.02881839,-0.009012882,O.01218354}; static int xl[length+20]; /*Low-pass filter floating point subroutine*/ void filter(int xin[], int xout[], int n, float h[]) {[/ font] int i, j; float sum; for(i=0;i for(i=0;i<length;i++) { sum=0.0; for(j=0 ;j xout=(int)sum; for(i=0;i<(nl);i++)x1[ni-2]=xin[length-1-i]; [color=# 000]} [backcolor=rgb (254, 254, 242)]/*main program*/ void main() FILE *fp1, *fp2; int frame,indata [length],outdata[length]; fp1=fopen(insp.dat, "rb");/* Input voice file*/ fp2= fopen(Outsp.dat,"wb");/* Voice file after filtering*/ [ font=Verdana, Arial, Helvetica, sans-serif]frame=0; while(feof(fp1) == 0) { frame++; printf(“frame=%d\n”,frame); [color=# 000]for(i=0;i<length;i++)indata=getw(fp1); /*Get a frame of voice data*/ [color=# 000]filter(indata, outdata, 19, h);/*Call low-pass filter subroutine*/[/ font] for(i=0; i<length ; i++) putw(outdata, fp2); /*Write the filtered sample values into the file*/ } fcloseall();/*Close file*/ [color= #000]return(0); [color=#000 ][font=Verdana, Arial,Example 1.8 Speech signal 800Hz 19-point FIR low-pass filter C language fixed-point program. #i nclude const int length=180; void filter (int xin[], int xout[], int n, int h[]); static int h[19]={399,-296,-945,-1555,-1503,-285,2112,5061,7503,8450, 7503,5061,2112,-285,-1503,-1555,-945,-296,399};/*Q15*/ static int x1[length+20]; /*Low-pass filter fixed-point subroutine*/ void filter(int xin[], int xout[], int n, int h[]) int i, j; long sum; for(i=0;i<length;i++)x1[n+i-111=xin]; [back color=rgb(254, 254, 242)]for(i=0;i<1ength;i++) sum=0;[/backcolor ] for(j=0;j<n;j++)sum+=(long)h[j]*x1[i-j+n-1]; [backcolor=r gb(254, 254, 242)]xout=sum>>15; for(i=0;i<(n-1);i++)x1[ni-2]=xin[length-i-1]; } [font=Verdana, Arial, 3 DSP Fixed-point arithmetic operations sans-serif] The numerical representation of fixed-point DSP chips is based on 2's complement representation. Each 16-bit number is represented by l sign bits, i integer bits, and 15-i fractional bits. Therefore: 00000010.10100000 represents the value: 21+2-1+2-3=2.625[ /backcolor] This number can be represented in Q8 format (8 decimal places), which has a range of values from -128 to +127.996. The decimal precision of a Q8 fixed-point number is 1/256 = 0.004. Although special cases (such as dynamic range and accuracy requirements) must use a mixed representation, it is more common to work with either all decimals represented in Q15 format or all integers represented in Q0 format. This is particularly true for signal processing algorithms that are primarily multiplication and accumulation, where decimals multiplied by decimals produce decimals and integers multiplied by integers produce integers. Of course, overflow may occur when multiplying and accumulating. In this case, the programmer should understand the physical process in mathematics to pay attention to possible overflow. Let's discuss DSP fixed-point operations of multiplication, addition and division. The assembly program takes TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, there are three cases: 1. Decimal multiplication 254, 242)]Example 1.9 Q15*Q15=Q30 0.5*0.5=0 .25 0.100000000000000; Q15 * 0.100000000000000;Q15 --------------------------------------------------[ /font] 00.010000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. : 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)25/Q15)25/Q15)25/Q15)25/Q15)Helvetica, sans-serif]00000010.10100000 The represented value is: 21+2- 1+2-3=2.625 Although special cases (such as dynamic range and accuracy requirements) must Use mixed representations. However, it is more common to work with either all fractional numbers in Q15 format or all integers in Q0 format. This is especially true for signal processing algorithms that are primarily multiplication and accumulation, where a fraction multiplied by a fraction equals a fraction. Integers multiplied by integers give integers. Of course, when multiplying and accumulating, overflow may occur. In this case, the programmer should understand the physics of the mathematics to be aware of possible overflow. Next we discuss the DSP fixed-point operations of multiplication, addition and division, and the assembly program takes TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, they can be divided into the following Three cases: 1. Decimal Multiply decimals Example 1.9 Q15*Q15=Q30 0.5*0.5=0.25 0.100000000000000; Q15 * 0.100000000000000; Q15 ---------------------------------------- ------- 00.010000000000000000000000000000=0.25; Q30 Multiplying two Q15 decimals gives a Q30 decimal, which means it has two signs. In general, the full-precision number obtained after multiplication does not need to be retained in its entirety, but only 16 bits of single-precision number 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)[/backcolor MPY OP2; oP2=4000H(0.5/Ql5) ] PAC SACH ANS, 1; ANS=2000H(0.25/Q15) Helvetica, sans-serif]00000010.10100000 The represented value is: 21+2- 1+2-3=2.625 Although special cases (such as dynamic range and accuracy requirements) must Use mixed representations. However, it is more common to work with either all fractional numbers in Q15 format or all integers in Q0 format. This is especially true for signal processing algorithms that are primarily multiplication and accumulation, where a fraction multiplied by a fraction equals a fraction. Integers multiplied by integers give integers. Of course, when multiplying and accumulating, overflow may occur. In this case, the programmer should understand the physics of the mathematics to be aware of possible overflow. Next we discuss the DSP fixed-point operations of multiplication, addition and division, and the assembly program takes TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, they can be divided into the following Three cases: 1. Decimal Multiply decimals Example 1.9 Q15*Q15=Q30 0.5*0.5=0.25 0.100000000000000; Q15 * 0.100000000000000; Q15 ---------------------------------------- ------- 00.010000000000000000000000000000=0.25; Q30 Multiplying two Q15 decimals gives a Q30 decimal, which means it has two signs. In general, the full-precision number obtained after multiplication does not need to be retained in its entirety, but only 16 bits of single-precision number 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)[/backcolor MPY OP2; oP2=4000H(0.5/Ql5) ] PAC SACH ANS, 1; ANS=2000H(0.25/Q15) sans-serif]The value represented is: 21+2-1+2-3=2.625 This number can be represented in Q8 format (8 decimal places), and the value range it represents is -128 to +l27.996. The decimal precision of a Q8 fixed-point number is 1/256=0.004. Special cases (such as dynamic range and precision requirements) necessitate the use of mixed representations. However, it is more common to work with either all fractional numbers represented in Q15 format or integers represented in Q0 format. This is particularly true for signal processing algorithms that are primarily multiplication and accumulation, where fractional numbers multiplied by fractional numbers yield fractional numbers, and integer numbers multiplied by integers yield integer numbers. Of course, overflow may occur when multiplying and accumulating, in which case the programmer should understand the physical processes in mathematics to be aware of possible overflows. Let's discuss DSP fixed-point operations for multiplication, addition, and division, and the assembly program uses the TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, there are three cases: 1. Decimal multiplication 254, 242)]Example 1.9 Q15*Q15=Q30 0.5*0.5=0 .25 0.100000000000000; Q15 * 0.100000000000000;Q15 --------------------------------------------------[ /font] 00.010000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. : 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)sans-serif]The value represented is: 21+2-1+2-3=2.625 This number can be represented in Q8 format (8 decimal places), and the value range it represents is -128 to +l27.996. The decimal precision of a Q8 fixed-point number is 1/256=0.004. Special cases (such as dynamic range and precision requirements) necessitate the use of mixed representations. However, it is more common to work with either all fractional numbers represented in Q15 format or integers represented in Q0 format. This is particularly true for signal processing algorithms that are primarily multiplication and accumulation, where fractional numbers multiplied by fractional numbers yield fractional numbers, and integer numbers multiplied by integers yield integer numbers. Of course, overflow may occur when multiplying and accumulating, in which case the programmer should understand the physical processes in mathematics to be aware of possible overflows. Let's discuss DSP fixed-point operations for multiplication, addition, and division, and the assembly program uses the TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, there are three cases: 1. Decimal multiplication 254, 242)]Example 1.9 Q15*Q15=Q30 0.5*0.5=0 .25 0.100000000000000; Q15 * 0.100000000000000;Q15 --------------------------------------------------[ /font] 00.010000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. : 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)004. Although special cases (such as dynamic range and accuracy requirements) must use mixed representations. However, it is more common to work with all fractions represented in Q15 format or integers represented in Q0 format. This is particularly true for signal processing algorithms that are mainly multiplication and accumulation. Fractions multiplied by fractions give fractions, and integers multiplied by integers give integers. Of course, overflow may occur when multiplying and accumulating. In this case, the programmer should understand the physical process in mathematics to pay attention to possible overflow. Let's discuss DSP fixed-point operations for multiplication, addition, and division. The assembly program takes TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, there are three cases: 1. Decimal multiplication 254, 242)]Example 1.9 Q15*Q15=Q30 0.5*0.5=0 .25 0.100000000000000; Q15 * 0.100000000000000;Q15 --------------------------------------------------[ /font] 00.010000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. : 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)004. Although special cases (such as dynamic range and accuracy requirements) must use mixed representations. However, it is more common to work with all fractions represented in Q15 format or integers represented in Q0 format. This is particularly true for signal processing algorithms that are mainly multiplication and accumulation. Fractions multiplied by fractions give fractions, and integers multiplied by integers give integers. Of course, overflow may occur when multiplying and accumulating. In this case, the programmer should understand the physical process in mathematics to pay attention to possible overflow. Let's discuss DSP fixed-point operations for multiplication, addition, and division. The assembly program takes TMS320C25 as an example. 3.1 Fixed-point multiplication When two fixed-point numbers are multiplied, there are three cases: 1. Decimal multiplication 254, 242)]Example 1.9 Q15*Q15=Q30 0.5*0.5=0 .25 0.100000000000000; Q15 * 0.100000000000000;Q15 --------------------------------------------------[ /font] 00.010000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. : 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)sans-serif]1. Multiply decimals Example 1.9 Q15*Q15=Q30 0.5*0.5=0.25 0.100000000000000;Q15 * 0.100000000000000; Q15 --- ----------------------------------------[ /color] 00.0100000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. 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)[/backcolor MPY OP2; oP2=4000H(0.5/Ql5) ] PAC SACH ANS, 1; ANS=2000H(0.25/Q15) sans-serif]1. Multiply decimals Example 1.9 Q15*Q15=Q30 0.5*0.5=0.25 0.100000000000000;Q15 * 0.100000000000000; Q15 --- ----------------------------------------[ /color] 00.0100000000000000000000000000000=0.25; Q30 After multiplying two Q15 decimals, you get a Q30 decimal, that is, there are two sign bits. In general, you don't have to keep all the full-precision numbers after multiplication, but only need to keep 16-bit single-precision numbers. 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)[/backcolor MPY OP2; oP2=4000H(0.5/Ql5) ] PAC SACH ANS, 1; ANS=2000H(0.25/Q15) Arial, Helvetica, sans-serif]MPY OP2;oP2=4000H(0.5/Ql5) [ font=Verdana, Arial, Helvetica, sans-serif]PAC SACH ANS, 1; ANS=2000H(0.25/Q15)Arial, Helvetica, sans-serif]MPY OP2;oP2=4000H(0.5/Ql5) [ font=Verdana, Arial, Helvetica, sans-serif]PAC SACH ANS, 1; ANS=2000H(0.25/Q15)
This post is from DSP and ARM Processors
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list