3. Subtraction operation of fixed-point number
Simply put, the principle of the various operations is to be the operation of the data to enlarge a certain number of times, in the process of operation of the magnified data, in the final need to output the results of the adjustment back.
For example, there are the following operations:
Copy Code code as follows:
...
COEFS1 = 0.023423; coefs2=0.2131
float COEFS1,COEFS2;
int result;
...
result = 34* coefs1+72* coefs2;
...
The code means that the module needs to output an integer result, but there are floating-point operations in the calculation. This code cannot be run if it is in a fixed-point DSP.
In order to solve this problem, we can do this: first of all, the COEFS1,COEFS2 and other similar floating-point data to expand a certain number of multiples (the specific expansion of how many times, according to the accuracy requirements of different), we temporarily move the decimal point to the right 4 digits, that is, the increase of multiples: * 10000, in the final output of the time in narrowing the same multiple. The modified code is roughly as follows:
Copy Code code as follows:
COEFS1 = 234; Coefs2= 2131
int COEFS1,COEFS2;
int result;
...
result = 34* coefs1+72* coefs2;
Result/= 10000;
...
Of course, the above example for everyone to understand, write may not be too correct, but the basic essence should be these. The specific processing process, we can search the Internet "3rd Chapter DSP Chip fixed-point operation. doc" This article, write very specific, here no longer wordy.
The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.