Sie sind auf Seite 1von 6

FSCA

Fast Sine calculating Algorithm


Author: Sahabaz Kathewadi, VIIth semester, KLESCET Belgaum, shabaz_129@yahoo.com
Abstract trigonometric functions have laid their greatest impact on the world of electronics; in this paper I have proposed an algorithm which calculates sine of any angle (in degrees) with an accuracy of 99.5% or more with respect to the standard values. The algorithm occupies lesser execution memory with respect to the presently known algorithm but has a very fast execution and is ideal for software as well as hardware implementation.

in this way if a look up table is prepared in memory and say we want to find the sine of 1.5 degree, it is compared and the value outputted is 0.017452 in place of 0.0261769, leading to an error of 49.99%. !!! This method gives accurate answers for certain discreet values, but fails unexpectedly if inputted values are not standard and it also involves unnecessary wastage of memory in making look up tables and time is wasted in comparisons. [5] iii. CORDIC Algorithm: it is an iterative arithmetic computing algorithm capable of evaluating various elementary functions using a unified shift and add approach. The basic concept of the CORDIC computation is to decompose the desired rotation angles such that the rotation through each of them can be accomplished with simple shift and add operations. [4][7] This method is the most preferred one in the hardware implementation because it does not involve any multipliers, however the major drawback of the method is, it is an iterative process and hence consumes more time (although less hardware area). FSCA can come over this problem of CORDIC without sacrificing much, with its other beneficial features. II. FSCA In this method I have made an attempt to minimize the number of calculations made and also to save lots of memory in the intermediate processing. The method is so simple that sine of any angle can be calculated without using a calculator or a computer within one minute with an accuracy of 99.5%, and the algorithm is so compatible that even an 8085 microprocessor can be programmed to give continuous sine values. The FSCA formula to calculate sine of an angle is: Sin(deg)= (deg * 0.02) (lap * 0.001) To understand this formula lets see its derivation, The C code to generate sine values at an successive angles of 0.1o , #include<stdio.h> #include<conio.h> #include<math.h> void main() { float val,deg,rad; for(deg=0;deg<=90;deg+=0.1) //incrementing degrees in steps of 0.1 { (1)

I.

INTRODUCTION

In todays technological climate, trigonometric functions are used at every point of calculation, right from the world of space navigation to the internet micro-architecture of chips (such as DSPs), these functions are invariantly used. Various methods have been proposed, some of the most commonly used methods are: i. Taylors series. ii. Look up table. iii. CORDIC algorithm. i. Taylors series: The series is given as, sin(x)=x-(x3/3!)+(x5/5!)-(x7/7!). This method is one of the oldest and most widely used, but the problem associated with this method is, to get values of higher accuracies, higher order factorial and powers has to be calculated. [6][3] For example: say to find sine of 179o, we have to find powers of 179, consider 1799, we get 1.886588917x 1020 , imagine what could be the values, that need to be stored if numbers of higher magnitude are given, and amount of memory and hardware that is wasted to store these intermediate results. And the second wastage of memory of hardware occurs to store the factorial terms, for example say 15!= 1.30767x1012 . Although this method calculates accurate values at higher iterations, it involves unnecessary wastage of memory to hold the intermediate results and take more time to give the desired output, due to iterative nature. ii. Look up table method: In this method standard sine values are stored in memory and whenever a value of angle has to be computed, it is compared with the values in the memory and most appropriate value is send. This method wastes lots of memory in storing the standard values, apart from that the answers obtained may not be always accurate. Consider the following example to illustrate this, sin(1)= 0.017452 sin(2)= 0.034899 sin(3)= 0.052335

rad=(deg*3.141592654)/180.0 //to convert degrees to radians val=sin(rad); // calculating sine from std function sin printf(" \n%f %f", deg,val); } getch(); } Degree 0.000000 0.100000 0.200000 0.300000 0.400000 0.500000 0.600000 0.700000 0.800000 0.900000 1.000000 1.100000 1.200000 1.300000 1.400000 1.500000 1.600000 1.700000 1.800000 1.900000 2.000000 2.100000 2.200000 2.300000 2.400000 2.500000 2.600000 2.700000 2.799999 2.899999 2.999999 3.099999 3.199999 3.299999 3.399999 3.499999 3.599999 3.699999 3.799999 3.899998 3.999998 4.099998 4.199998 4.299998 4.399998 4.499998 Sine(degree) 0.000000 0.001745 0.003491 0.005236 0.006981 0.008727 0.010472 0.012217 0.013962 0.015707 0.017452 0.019197 0.020942 0.022687 0.024432 0.026177 0.027922 0.029666 0.031411 0.033155 0.034899 0.036644 0.038388 0.040132 0.041876 0.043619 0.045363 0.047106 0.048850 0.050593 0.052336 0.054079 0.055821 0.057564 0.059306 0.061049 0.062790 0.064532 0.066274 0.068015 0.069756 0.071497 0.073238 0.074979 0.076719 0.078459

4.599998 0.080199 4.699998 0.081938 4.799998 0.083678 4.899998 0.085417 4.999998 0.087156 5.099998 0.088894 5.199997 0.090633 5.299997 0.092371 5.399997 0.094108 5.499997 0.095846 5.599997 0.097583 5.699997 0.099320 89.899200 0.999998 89.999199 1.000000 If we make a careful observation of the above output, one can easily notice that the sine value almost changes in steps of 0.001746 or approximately 0.002, hence the output is an Arithmetic progression (AP) with a difference of 0.002, Sin(deg) = initial + (final -1)* difference Initial value= 0; Final value = deg +1; Difference= 0.002; Therefore equation 2 becomes, Sin(deg) = (deg * 0.002); (3) (2)

Since the difference is calculated at a successive angle of 0.1 degree, we need to multiply deg by 10; Therefore equation 3 becomes; Sin(deg) = (deg * 0.02) (4)

but if we observe in later value say at 1o , the value does not satisfy the AP equation, hence there is another factor that is governing the value, that reduces the value of AP at successive stages, I have named this factor as Lap, and value of this lap is 0.001 by observation and approximation, and the lap rate is not constant it increases as we move from 0 to 90, by careful observations I have found the lap rates at an interval of every 10o , and with their substitution correct answers are obtained, hence by applying the correction in equation 4 we get, sin(deg) = (deg * 0.02) ( lap * 0.001) The frequency of lap rate at an interval of 10o is given below, TABLE 1. Interval in degrees Size of lap per degree 0 - 10 10 - 20 20 - 30 30 - 40 40 - 50 50 - 60 2.6352 3.16278 4.20202 5.721 7.67455 10.00145

60 - 70 70 - 80 80 - 90

12.6337 15.48852 18.48078

The intervals above appear to overlap but they are not so, here we are calculating values at a precision of 0.1o one size of lap ends at say 9.90 and other starts at 10.0o, hence they appear to overlap. Total lap per 10o is shown in below, TABLE 2. Degrees Size of total lap 10 20 30 40 50 60 70 80 90 26.352 57.9798 100 157.21 233.9555 333.97 460.307 615.1922 800

void main() { float fsca,deg=0.1,lap=0.26352,sinval,accu,rad; clrscr(); while(deg<30.0) { if(deg<=10.0) { fsca=(deg*0.02)-(lap*0.001); lap+=0.26352; } else if(deg>10.0 && deg<=20.0) { fsca=(deg*0.02)-(lap*0.001); lap+=0.316278; } else if(deg>20.0 && deg<=30.0) { fsca=(deg*0.02)-(lap*0.001); lap+=0.420202; } else if(deg>30.0 && deg<=40.0) { fsca=(deg*0.02)-(lap*0.001); lap+=0.5721; } else if(deg>40.0 && deg<=50.0) { fsca=(deg*0.02)-(lap*0.001); lap+=0.767455; } else if(deg>50.0 && deg<=60.0) { fsca=(deg*0.02)-(lap*0.001); lap+=1.000145; } else if(deg>60.0 && deg<=70.0) { fsca=(deg*0.02)-(lap*0.001); lap+=1.26337; } else if(deg>70.0 && deg<=80.0) { fsca=(deg*0.02)-(lap*0.001); lap+=1.548852; } else if(deg>80.0 && deg<=90.0) { fsca=(deg*0.02)-(lap*0.001); lap+=1.848078; } rad=(deg*3.141592654)/180.0; sinval=sin(rad); accu=(fsca/sinval)*100;

Illustration, Calculate sine of 15.5o , I suggest you first calculate using other methods and then try FSCA and check out the difference. Solution: Deg = 15.5 To calculate lap, 15.5 = 10 + 5.5 From table 1 and 2, Lap = ( 26.352) + ( 5.5 * 3.16278) Lap = 43.74729. From equation 1; Sin(deg) = (deg * 0.02) (lap * 0.001) Sin(15.5) = (15.5 * 0.02) (43.74729 * 0.001) Sin(15.5) = 0.26625271 And the standard answer is : 0.2672383761, Accuracy = (0.2672383761/0.26625271)*100; Accuracy = 99.63116597% You can check out with any angle youll get accuracy above 99.5%. /*............FSCA..............*/ #include<conio.h> #include<stdio.h> #include<time.h> #include<dos.h> #include<math.h>

printf("\n%f %f deg+=0.1; } getch(); }

%f",deg,fsca,accu);

Output of the above code is,

Degrees 0.100000 0.200000 0.300000 0.400000 0.500000 0.600000 0.700000 0.800000 0.900000 1.000000 1.100000 1.200000 1.300000 1.400000 1.500000 1.600000 1.700000 1.800000 1.900000 2.000000 2.100000 2.200000 2.300000 2.400000 2.500000 2.600000 2.700000 2.799999 2.899999 2.999999 3.099999 3.199999 3.299999 3.399999 3.499999 3.599999 3.699999 3.799999 3.899998 3.999998 4.099998 4.199998 4.299998

sin(deg) 0.001736 0.003473 0.005209 0.006946 0.008682 0.010419 0.012155 0.013892 0.015628 0.017365 0.019101 0.020838 0.022574 0.024311 0.026047 0.027784 0.029520 0.031257 0.032993 0.034730 0.036466 0.038203 0.039939 0.041676 0.043412 0.045148 0.046885 0.048621 0.050358 0.052094 0.053831 0.055567 0.057304 0.059040 0.060777 0.062513 0.064250 0.065986 0.067723 0.069459 0.071196 0.072932 0.074669

Percentage Accuracy 99.493034 99.493179 99.493423 99.493790 99.494240 99.494797 99.495445 99.496208 99.497070 99.498032 99.499084 99.500252 99.501518 99.502876 99.504341 99.505898 99.507576 99.509346 99.511215 99.513199 99.515266 99.517433 99.519707 99.522087 99.524551 99.527138 99.529808 99.532585 99.535477 99.538452 99.541534 99.544724 99.548004 99.551392 99.554878 99.558464 99.562157 99.565941 99.569847 99.573845 99.577927 99.582130 99.586433

4.399998 4.499998 4.599998 4.699998 4.799998 4.899998 4.999998 5.099998 5.199997 5.299997 5.399997 5.499997 5.599997 5.699997 5.799997

0.076405 0.078142 0.079878 0.081615 0.083351 0.085087 0.086824 0.088560 0.090297 0.092033 0.093770 0.095506 0.097243 0.098979 0.100716

99.590836 99.595329 99.599930 99.604630 99.609436 99.614349 99.619354 99.624474 99.629684 99.635002 99.640419 99.645935 99.651550 99.657265 99.663086

The above output proves the accuracy of the algorithm. If you dont want to use any loops or too many if conditions in your program, you can take the lap parameters and find a polynomial using Newton - Gregory backward interpolation formula. This will save lot of hardware memory, shortens the program and add to faster execution. [1] Without Calculator The question that must be obviously arising in you mind is that, in begin I had told we can calculate sine values without a calculator or computer, but how can we do it, its explain below. Its really difficult to remember high precision floating point numbers so some approximation have to be done in remembering the lap rates, the approximations are given below, TABLE 3. Uptill in degrees Lap size 10 20 30 40 50 60 70 80 90 26 58 100 157 234 334 460 615 800

I hope its easy to remember the above table, now say you want to find sine of 49o, Solution, Try doing this without using a calculator, 49 falls inbetween 40-50, Lap range between 40-50 is= 234 157 =77 Divide this lap range by 10 that will give you 7.7 Now 7.7 is the increment of lap for every one degree form 40 to 50, therefore for 49 the total lap is,

Lap = (lap till 40) + (increase in lap till 49) = (157) + (9 * 7.7) 226.3. Form equation 1 we have, Sin(deg) = (deg * 0.02) (lap * 0.001); The multiplier in above equations is just 1 and 2 hence not much efforts are needed to perform the calculation, Here there is another trick to calculate that I use, First perform, deg * 2 49 * 2 = 98. Shift it across one decimal place, because we actually need to multiply by 0.02 so shifting is done , i.e. 0.98 To perform (0.001 * lap), Just perform two shifting across decimal place i.e. 0.2263. Now you have got two terms of the equation 1 now just perform the subtraction, Sin(49) = 0.98 0.2263, = 0.7537 Accuracy = 99.86622931% Try out with different values, you speed up further with little practice to handle decimal numbers. III. RESULTS The algorithm was implemented in DSP kits using Chipmax technology. The lap rate is kept at 10o. The resulting graphs are shown below:
Fig.3. Error between accurate and FSCA (note error is in terms of 10-18) Fig.2. Output of Math.h sine function in DSP kit.

Results with 5 deg lap interval programmed in C. TABLE 4. FSCA 4K Math.h in C 12K Taylor series 20K

Memory for execution Average time For 90,00,000 executions Minimum Accuracy IV.

1.208791 99.9%

1.318681 Reference so 100%

2.197802 99.92%

CONCLUSION

Fig.1. Output of FSCA uptill 90 deg in DSP kit

The algorithm works faster than presently known algorithms, with required accuracy and precision. The algorithm is ideal for both hardware and software implementation, since it has shown good results in both C and DSP kit. Experiments have shown that it consumes very less memory compared to other algorithms and have maximum speed of execution. The algorithm does not involve any kind of iterations, hence instant results are possible.

V.

FUTURE SCOPE

The algorithm can be used to fabricate Application Specific Integrated Circuits (ASIC) for various computational purposes (In fact Im presently working on the same). If implemented for the DSP oriented calculation, lots silicon can be saved as it require lesser hardware (because it needs less number of multipliers) and computational speed (such as FFT, DFFT, IDFFT, DCT etc) can be significantly increased. Since no iterations are performed, the algorithm gives instant results which are accurate by at least 99.5% (accuracy can be further increased if lap size is decreased), the algorithm can be even used in combination of some other algorithm (like CORDIC), to get highest accurate result in shortest time (because the initial value will be very close to accurate value, got by FSCA). [4][6] VI. APPLICATIONS

The method discussed above can be used universally to find any trigonometric function, in fact the main application of it is, it can be use to transform any signal into an equation with lap parameters and transmit just the lap parameters, at the receiving side the signal can be reconstructed (with an accuracy of 99.5% and above based upon the lap selected). This transformation can also be used to store data in a very compact form. Further it can be used in DSPs and AISC industries, for various transformations (like FFT, DFFT etc).[2] AKNOWLEDGEMENTS I would like to thank my Master, my teacher and my mental support Prof. Hansraj Guhilot sir, who has iterated me, with every tool that he pose to make me more and more technically fit and ready to face the real world. I would also like to thank Manthan Semiconductors, whose project idea thrilled me to do this work. REFERENCES
[1] [2] [3] [4] Dr. B. S. Grewal, Higher Engineering Mathematics, 34th edition, Khanna Publishers, 2000, pp 668-681. K.K. Parhi, VLSI Digital Signal Processing, Design and implementation, wiley and sons, 1999, Cahpter. 7. Kreyzig, Advance Engineering Mathematics, 5nd edition, Wiley Eastern Private Limited, July 1998, pp 6930694. M.D.Ercegovac, T.Lang, Fast Cosine/Sine Implementation using CORDIC iterations, IEEE Trans. On Comput., vol.40, n 9, 1987, pp.222-226. Muhammad Ali Mazidi and Janice Ali Mazidi, The 8051 Microcontroller and Embedded Systems, 14th Indain reprint, Pearson Prentice Hall, 2005, pp 281-282. Thomas and Finney, Calculus and Analytic Geometry, 6th edition, 13th Indian reprint, Narosa Publishing House, 1998, pp 663-671. Yu Hen Hu, CORDIC-Based VLSI Architecture for Digital Signal Processing, IEEE Signal Processing Magazine, July 1992, pp 17-19.

[5]

[6] [7]

Das könnte Ihnen auch gefallen