Closed ndsl7109256 closed 2 months ago
glibc implementation of sincos
:
@ndsl7109256 Hey! You do a great job!
Here is a suggestion make your report getting better.
When mentioning RMS or MSE, be sure to include the number of observations.
Enhancement: Implement CORDIC algorithm for tan calculation
Currently, the twin_tan
function uses division, which may be computationally expensive. A potential improvement would be to implement the CORDIC algorithm for calculating tan. This would avoid the use of the divider and potentially improve performance.
References: https://github.com/Max-Gulda/Cordic-Math/blob/main/lib/cordicMath/src/cordic-math.c#L290-L332 https://hackmd.io/@sysprog/linux-intdiv
Thank @ndsl7109256 for contributing!
The previous implementation used the pre-calculated fixed-point arithmetic table for sine values, which added over 2 KiB to the code size.
To solve this issue, I implemented the 5th order polynomial approximation for sine, which reduced the code size from 2556 bytes to 494 bytes (by about 80%) while maintaining acceptable error (RMS error is 8.866 observed with 0-90 degrees, 0-1024 in fixed-point representation)
Original code size with sine table.
Code size after using 5th order approximation
I initially tried a 3rd order approximation, but the error was slightly large, causing the drawn circle to appear not perfectly round. Below is some analysis.
ref: https://www.nullhardware.com/blog/fixed-point-sine-and-cosine-for-embedded-systems/ https://hackmd.io/@rickywu0421/FinalProject#透過-3rd-order-sine-approximation-模擬-RSSI