Trigonometric functions are commonly used in real-time control applications, particularly within the inner loops of control algorithms, where speed and accuracy is essential. The performance of trigonometric functions is a key careabout for designers of these systems as it can have a significant impact on the overall performance of the system. Until recently, trignometric functions based on lookup tables were considered faster than the polynomial-based methods; however, with the inclusion of floating-point units (FPUs) and faster clock speeds, polynomial-based approximations have gained favor. TI has developed C functions of the most commonly used trigonometric functions using these polynomial-based methods and has optimized them for TI's Arm®-based microcontrollers (MCUs) and microprocessors (MPUs). This application note surveys the trigonometric functions that are available today and shares the optimization techniques used in these functions, as well as the results of our optimization efforts.
The TI-optimized trigonometric functions presented in this document can be found in MCU+ SDK v8.5 and later.
Arm® and Cortex® are registered trademarks of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
All trademarks are the property of their respective owners.
Trigonometric functions are commonly used in real-time control applications, particularly within the inner loops of control algorithms, where speed and accuracy is essential. The performance of trigonometric functions is a key careabout for designers of these systems as it can have a significant impact on the overall performance of the system. Until recently, trignometric functions based on lookup tables were considered faster than the polynomial-based methods; however, with the inclusion of floating-point units (FPUs) and faster CPU clock speeds, polynomial-based approximations are gaining favor.
The most commonly used trigonometric functions are sine, cosine, arcsine, arccosine, arctangent, and atan2. Trigonometric optimization techniques for these functions fall into two categories:
These techniques are described in the following sections and the polynomial-based optimization techniques used by the TI Arm® Trigonometric Library are discussed.
Up until recently, lookup table-based approximations were considered faster than polynomial-based approximations. Lookup table-based approximations pre-compute N values of the target function and then index them into the table to select the two closest points and perform an interpolation between them. When using lookup table-based approximations, the accuracy can be adjusted by changing either the size of the lookup or the order of the interpolation function. However, this comes with the tradeoff of more memory usage and longer function times. This is the technique used by the Fast Math Functions in the Arm CMSIS Library where they use a table size of 512 entries to cover 0-2PI and then do a linear interpolation between the closest values.
With the inclusion of floating-point co-processors and faster clock speeds, the polynomial-based methods are now quite fast and have the added benefit of not requiring any table storage. The TI Arm Trig Library uses this method.
The first step in using polynomial approximations is to reduce the range of the input. The bigger the range needed to approximate, the higher order polynomial needed to achieve a specified level of accuracy, which means more computations and slower function performance.
The second step is to compute the approximation for the reduced range and then finally restore the range depending on which quadrant the input was originally in by using trigonometric identities.
There are a number of methods of finding the best polynomials to achieve the lowest error with the fewest terms, but the most commonly used is the minimax approximation algorithm and one version in particular: the Remez algorithm. The Remez algorithm is used to find a polynomial with the least maximum error. This polynomial is called a minimax polynomial. The minimax polynomial is what is used in our optimized trigonometric functions as it is ideal for control applications where worst-case performance is a key care-about.