Fast and Accurate Approximation Methods for Trigonometric and Arctangent Calculations for Low-Performance Computers
Abstract
:1. Introduction
2. Concept of Approximation by Residual Correction Method
- (1).
- Linear approximation with fixed origin and domain endpoints:
- (2).
- Evaluate residuals with approximate target function:
- (3).
- Design of residual correction function (RCF):
- (4).
- Approximate formula with residual correction:
3. Second Approximation by the Residual Correction Method for Trigonometric Functions
3.1. Exploring RCF Candidates
- (1).
- RCF with signed quadratic function:
- (2).
- RCF with cubic function:
- (3).
- RCF with co-function:
3.2. Second Approximation of Trigonometric Functions
4. Second Approximation by the Residual Correction Method for Inverse Trigonometric Functions
4.1. Domain Expansion
4.2. Exploring RCF Candidates
4.3. Second Approximation of Inverse Trigonometric Functions
5. Results
6. Discussion
6.1. Approximation of Trigonometric Function
6.2. Approximation of Inverse Trigonometric Function
7. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Moroz, L.; Samotyy, V. Efficient Floating-Point Division for Digital Signal Processing Application [Tips &Tricks]. IEEE Signal Process. Mag. 2019, 36, 159–163. [Google Scholar] [CrossRef]
- Liu, W.; Nannarelli, A. Power Efficient Division and Square Root Unit. IEEE Trans. Comput. 2012, 61, 1059–1070. [Google Scholar] [CrossRef]
- Viitanen, T.; Jääskeläinen, P.; Esko, O.; Takala, J. Simplified floating-point division and square root. In Proceedings of the 2013 IEEE International Conference on Acoustics, Speech and Signal Processing, Vancouver, BC, Canada, 26–31 May 2013; pp. 2707–2711. [Google Scholar] [CrossRef]
- Marius, C. Intel® AVX-512 Instructions and Their Use in the Implementation of Math Functions. Available online: http://www.fit.vutbr.cz/~iklubal/IPA/AVX-512_Cornea.pdf (accessed on 24 April 2022).
- Saber, M.; Jitsumatsu, Y.; Kohda, T. A low-power implementation of arctangent function for communication applications using FPGA. In Proceedings of the 2009 Fourth International Workshop on Signal Design and its Applications in Communications, Fukuoka, Japan, 19–23 October 2009; pp. 60–63. [Google Scholar] [CrossRef]
- Oberman, S.; Flynn, M. Design issues in division and other floating-point operations. IEEE Trans. Comput. 1997, 46, 154–161. [Google Scholar] [CrossRef] [Green Version]
- Instruction Tables: Lists of Instruction Latencies, Throughputs and Micro-Operation Breakdowns for Intel, AMD and VIA CPUs. Available online: https://www.agner.org/optimize/ (accessed on 17 May 2022).
- PIC® MCUs | Microchip Technology. Available online: https://www.microchip.com/en-us/products/microcontrollers-and-microprocessors/8-bit-mcus/pic-mcus (accessed on 4 July 2022).
- 8-Bit Microcontroller Based SOC Chip for Drone, Robot, and Many More Applications. Available online: https://www.eeherald.com/section/new-products/owns20170312003-8-bit-mcu-soc-np.html (accessed on 4 July 2022).
- The 8-Bit Microcontroller and Beyond: An Interview with Tam Hanna. Available online: https://www.elektormagazine.com/news/8-bit-microcontroller-interview-tam-hanna (accessed on 4 July 2022).
- Bolanakis, D.E. A Survey of Research in Microcontroller Education. IEEE Rev. Iberoam. Tecnol. Del Aprendiz. 2019, 14, 50–57. [Google Scholar] [CrossRef]
- Buturugă, A.; Constantinescu, R.C.; Stoichescu, D.A. Current consumption analysis for 8-bit microcontrollers. In Proceedings of the 2019 11th International Conference on Electronics, Computers and Artificial Intelligence (ECAI), Pitesti, Romania, 27–29 June 2019; pp. 1–6. [Google Scholar] [CrossRef]
- Moyer, B. MPU Vs. MCU. 2020. Available online: https://semiengineering.com/mpu-vs-mcu/ (accessed on 4 July 2022).
- Chen, C.H.; Lin, M.Y.; Liu, C.C. Edge Computing Gateway of the Industrial Internet of Things Using Multiple Collaborative Microcontrollers. IEEE Netw. 2018, 32, 24–32. [Google Scholar] [CrossRef]
- Joo, S.; An, Y.J.; Oh, T.W.; Jung, S.O. Comparative analysis of MCU memory for IoT application. In Proceedings of the 2018 International Conference on Electronics, Information, and Communication (ICEIC), Honolulu, HI, USA, 24–27 January 2018; pp. 1–3. [Google Scholar] [CrossRef]
- Altitude Data for Drone Navigation: A Compact Barometric Pressure Sensor and Thermometer from Bosch—News. Available online: https://www.allaboutcircuits.com/news/drone-altitude-bmp388-barometric-pressure-sensor-thermometer-bosch/ (accessed on 4 July 2022).
- Alakananda, B.G.; Venugopal, N. Development of a Programmable System on Chip(Psoc) based Quadcopter. In Proceedings of the 2020 4th International Conference on Trends in Electronics and Informatics (ICOEI)(48184), Tirunelveli, India, 15–17 June 2020; pp. 93–98. [Google Scholar] [CrossRef]
- An IIR Filter in an 8-bit Microcontroller. Available online: http://e-rokodelnica.si/A003/A003_EN.html (accessed on 4 July 2022).
- Leong, B.T.M.; Low, S.M.; Ooi, M.P.L. Low-Cost Microcontroller-based Hover Control Design of a Quadcopter. Procedia Eng. 2012, 41, 458–464. [Google Scholar] [CrossRef] [Green Version]
- Cococcioni, M.; Rossi, F.; Ruffaldi, E.; Saponara, S. Fast Approximations of Activation Functions in Deep Neural Networks when using Posit Arithmetic. Sensors 2020, 20, 1515. [Google Scholar] [CrossRef] [PubMed] [Green Version]
- Romeric. Fastapprox: Approximate and Vectorized Versions of Common Mathematical Functions. Available online: https://github.com/romeric/fastapprox (accessed on 25 April 2022).
- Bouguezzi, S.; Faiedh, H.; Souani, C. Hardware Implementation of Tanh Exponential Activation Function using FPGA. In Proceedings of the 2021 18th International Multi-Conference on Systems, Signals Devices (SSD), Monastir, Tunisia, 22–25 March 2021; pp. 1020–1025. [Google Scholar] [CrossRef]
- Tsmots, I.; Skorokhoda, O.; Rabyk, V. Hardware Implementation of Sigmoid Activation Functions using FPGA. In Proceedings of the 2019 IEEE 15th International Conference on the Experience of Designing and Application of CAD Systems (CADSM), Polyana, Ukraine, 26 February–2 March 2019; pp. 34–38. [Google Scholar] [CrossRef]
- Chang, C.H.; Chen, S.H.; Chen, B.W.; Wang, J.C.; Wang, J.F. A division-free algorithm for fixed-point power exponential function in embedded system. In Proceedings of the 2013 1st International Conference on Orange Technologies (ICOT), Tainan, Taiwan, 12–16 March 2013; pp. 223–226. [Google Scholar] [CrossRef]
- Warren, H.S. Hacker’s Delight, 2nd ed.; Pearson Education: London, UK, 2013. [Google Scholar]
- Blinn, J. Floating-point tricks. IEEE Comput. Graph. Appl. 1997, 17, 80–84. [Google Scholar] [CrossRef]
- Moroz, L.V.; Samotyy, V.V.; Horyachyy, O.Y. Modified Fast Inverse Square Root and Square Root Approximation Algorithms: The Method of Switching Magic Constants. Computation 2021, 9, 21. [Google Scholar] [CrossRef]
- Walczyk, C.J.; Moroz, L.V.; Cieśliński, J.L. Improving the Accuracy of the Fast Inverse Square Root by Modifying Newton–Raphson Corrections. Entropy 2021, 23, 86. [Google Scholar] [CrossRef] [PubMed]
- Eberly, D.H. GPGPU Programming for Games and Science; A K Peters/CRC Press: New York, NY, USA, 2014. [Google Scholar] [CrossRef]
- id-Software/Quake-III-Arena. 2022. Available online: https://github.com/id-Software/Quake-III-Arena/blob/dbe4ddb10315479fc00086f08e25d968b4b43c49/code/game/q_math.c (accessed on 24 April 2022).
- Lomont, C. Fast Inverse Square Root; Technical-315 Report, Volume 32; 2003. Available online: http://www.matrix67.com/data/InvSqrt.pdf (accessed on 5 July 2022).
- Robertson, M. A Brief History of InvSqrt. Bachelor’s Thesis, University of New Brunswick, Fredericton, NB, Canada, 2012. [Google Scholar]
- Lyons, R.G. Efficient Approximations for the Arctangent Function. In Streamlining Digital Signal Processing: A Tricks of the Trade Guidebook; IEEE: Piscataway, NJ, USA, 2012; pp. 265–276. [Google Scholar] [CrossRef]
- Abrarov, S.M.; Quine, B.M. A rational approximation of the arctangent function and a new approach in computing pi. arXiv 2016, arXiv:1603.03310. [Google Scholar]
- Ukil, A.; Shah, V.H.; Deck, B. Fast computation of arctangent functions for embedded applications: A comparative analysis. In Proceedings of the 2011 IEEE International Symposium on Industrial Electronics, Gdansk, Poland, 27–30 June 2011; pp. 1206–1211. [Google Scholar] [CrossRef]
- Girones, X.; Julia, C.; Puig, D. Full Quadrant Approximations for the Arctangent Function [Tips and Tricks]. IEEE Signal Process. Mag. 2013, 30, 130–135. [Google Scholar] [CrossRef]
- Benammar, M.; Alassi, A.; Gastli, A.; Ben-Brahim, L.; Touati, F. New Fast Arctangent Approximation Algorithm for Generic Real-Time Embedded Applications. Sensors 2019, 19, 5148. [Google Scholar] [CrossRef] [PubMed] [Green Version]
- Haviland, G.; Tuszynski, A. A CORDIC Arithmetic Processor Chip. IEEE J. Solid-State Circuits 1980, 15, 4–15. [Google Scholar] [CrossRef] [Green Version]
- Zhu, H.; Ge, Y.; Jiang, B. Modified CORDIC algorithm for computation of arctangent with variable iterations. In Proceedings of the 2016 IEEE 13th International Conference on Signal Processing (ICSP), Chengdu, China, 6–10 November 2016; pp. 261–264. [Google Scholar] [CrossRef]
- Pilato, L.; Fanucci, L.; Saponara, S. Real-Time and High-Accuracy Arctangent Computation Using CORDIC and Fast Magnitude Estimation. Electronics 2017, 6, 22. [Google Scholar] [CrossRef] [Green Version]
- Kusaka, T.; Tanaka, T.; Kajiwara, H. Residual Correction Method for Fast Calculation of Arctangent in Embedded Systems. In Proceedings of the IEEE/ASME International Conference on Advanced Intelligent Mechatronics, Busan, Korea, 7–11 July 2015; p. 6. [Google Scholar]
- DSP Trick: Fixed-Point Atan2 With Self Normalization. Available online: https://dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization/ (accessed on 25 April 2022).
- Tsuchiya, Y.; Imamura, Y.; Tanaka, T.; Kusaka, T. Estimating Lumbar Load During Motion with an Unknown External Load Based on Back Muscle Activity Measured with a Muscle Stiffness Sensor. J. Robot. Mechatronics 2018, 30, 696–705. [Google Scholar] [CrossRef]
- Tsuchiya, Y.; Kusaka, T.; Tanaka, T.; Matsuo, Y. Wearable Sensor System for Lumbosacral Load Estimation by Considering the Effect of External Load. In Advances in Human Factors in Wearable Technologies and Game Design; Ahram, T., Falcão, C., Eds.; Advances in Intelligent Systems and Computing; Springer International Publishing: Cham, Switzerland, 2018; pp. 160–168. [Google Scholar] [CrossRef]
- Kusaka, T.; Tanaka, T.; Kaneko, S.; Suzuki, Y.; Saito, M.; Kajiwara, H. Assist Force Control of Smart Suit for Horse Trainers Considering Motion Synchronization. Int. J. Autom. Technol. 2009, 3, 723–730. [Google Scholar] [CrossRef]
- Yoshida, M.; Tanaka, T.; Tsuchiya, Y.; Kusaka, T. Reducing Lumbar Load with Active Corset. J. Robot. Mechatronics 2018, 30, 740–751. [Google Scholar] [CrossRef]
- Hashimoto, K.; Tanaka, T.; Kusaka, T. Walking Assistance and Resistance of Walking Motion by Trunk and Pelvis Motion Assist. In Proceedings of the 2018 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), Madrid, Spain, 1–5 October 2018; pp. 8597–8602. [Google Scholar] [CrossRef]
- Berry, N. Approximating the Sine Function. 2019. Available online: https://datagenetics.com/blog/july12019/index.html (accessed on 6 July 2022).
- Cordes, P. Answer to “Is It Still Worth Using the Quake Fast Inverse Square Root Algorithm Nowadays on x86-64?”. 2022. Available online: https://stackoverflow.com/a/71608406 (accessed on 9 July 2022).
- Hasnat, A.; Bhattacharyya, T.; Dey, A.; Halder, S.; Bhattacharjee, D. A fast FPGA based architecture for computation of square root and Inverse Square Root. In Proceedings of the 2017 Devices for Integrated Circuit (DevIC), Kalyani, India, 23–24 March 2017; pp. 383–387. [Google Scholar] [CrossRef]
1st Approx. | 2nd Approx. | Math Library (math.h) | |
---|---|---|---|
Sine function | 0.54 ± 0.16 ns | 1.4 ± 0.2 ns | 68.28 ± 0.52 ns |
Cosine function | 1.22 ± 0.13 ns | 2.04 ± 0.39 ns | 69.1 ± 0.90 ns |
1st Approx. | 2nd Approx. at2if/at2ex | 2nd Approx. with FISR at2nif/at2nex | Math Library (math.h) | |
---|---|---|---|---|
Calculation time | 1.43 ± 0.26 ns | 2.96 ± 0.27 ns 4.76 ± 0.26 ns | 7.3 ± 0.19 ns 9.14 ± 0.25 ns | 21.96 ± 0.83 ns |
Sine Function | Maximum Error | Computational Cost |
---|---|---|
RCM 1st approximation | 5.6 × 10−2 | 1 addition 2 multiplications 1 absolute value |
RCM 2nd approximation | 9.2 × 10−4 | 2 additions 4 multiplications 2 absolute values |
Atan2 Function | Maximum Error | Computational Cost |
---|---|---|
RCM 1st approximation | 4.2 × 10−2 rad | 1 addition 2 multiplications |
RCM 2nd approximation | 9.2 × 10−4 rad | 7 additions 14 multiplications 4 absolute values |
Taylor Series (Original/Optimized for Embedding) | Proposed Method | ||||||
---|---|---|---|---|---|---|---|
1st Order | 3rd Order | 5th Order | 7th Order | 9th Order | 1st Approx | 2nd Approx | |
Maximum abolute error | 3.14 | 2.03 | 5.24 × 10−1 | 7.52 × 10−2 | 6.93 × 10−3 | 5.6 × 10−2 | 9.2 × 10−4 |
Mean absolute error | 5.84 | 2.25 | 4.23 ×10−1 | 3.66 | 1.9 | 3.3 | |
Number of multiplication | 0/0 | 3/3 | 8/4 | 15/5 | 24/6 | 2 | 4 |
Atan2 Approx. Methods | Accuracy | Division | Iteration | Memory |
---|---|---|---|---|
Rational approx. [34] | High | Necessary | - | - |
Tayler expansion | Depends on order | - | - | - |
LUT | Depends on memory | - | - | Large |
CORDIC [38] | Depends on iteration | Necessary | Necessary | - |
DSP-trick [42] | Middle (<0.01) | Necessary | - | - |
RCM 1st approx. | Middle (<0.01) | - | - | - |
RCM 2nd approx. * | High (<0.001) | - | - | - |
Grade | Example of MCU | Available Program Memory | Proposed Methods | Math Library (math.h) | ||
---|---|---|---|---|---|---|
1 KB Required | (w/s2 and c2) 1.8 KB req’d | atan2 Only 3 KB req’d | atan2, sin, cos 7.7 KB req’d | |||
Low | PIC12F1572 | 2 KB | A | AR | CC | CC |
Middle | PIC16F1827 | 4 KB | A | A | AR | CC |
Middle | PIC16F1769 | 8 KB | A | A | A | AR |
High | PIC18F2580 | 16 KB | A | A | A | A |
1st Approx of atan2 | 2nd Approx of atan2 | atan2 (math.h) | |
---|---|---|---|
Average time of 100 iterations | 1.5 ms | 6.5 ms | 8.0 ms |
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |
© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Kusaka, T.; Tanaka, T. Fast and Accurate Approximation Methods for Trigonometric and Arctangent Calculations for Low-Performance Computers. Electronics 2022, 11, 2285. https://doi.org/10.3390/electronics11152285
Kusaka T, Tanaka T. Fast and Accurate Approximation Methods for Trigonometric and Arctangent Calculations for Low-Performance Computers. Electronics. 2022; 11(15):2285. https://doi.org/10.3390/electronics11152285
Chicago/Turabian StyleKusaka, Takashi, and Takayuki Tanaka. 2022. "Fast and Accurate Approximation Methods for Trigonometric and Arctangent Calculations for Low-Performance Computers" Electronics 11, no. 15: 2285. https://doi.org/10.3390/electronics11152285
APA StyleKusaka, T., & Tanaka, T. (2022). Fast and Accurate Approximation Methods for Trigonometric and Arctangent Calculations for Low-Performance Computers. Electronics, 11(15), 2285. https://doi.org/10.3390/electronics11152285