Sine Cosine
- RISCV_DSP_ATTRIBUTE void riscv_sin_cos_f32 (float32_t theta, float32_t *pSinVal, float32_t *pCosVal)
- RISCV_DSP_ATTRIBUTE void riscv_sin_cos_q31 (q31_t theta, q31_t *pSinVal, q31_t *pCosVal)
- group SinCos
Computes the trigonometric sine and cosine values using a combination of table lookup and linear interpolation. There are separate functions for Q31 and floating-point data types. The input to the floating-point version is in degrees while the fixed-point Q31 have a scaled input with the range [-1 0.9999] mapping to [-180 +180] degrees.
The floating point function also allows values that are out of the usual range. When this happens, the function will take extra time to adjust the input value to the range of [-180 180].
The result is accurate to 5 digits after the decimal point.
The implementation is based on table lookup using 360 values together with linear interpolation. The steps used are:
Calculation of the nearest integer table index.
Compute the fractional portion (fract) of the input.
Fetch the value corresponding to
index
from sine table toy0
and also value fromindex+1
toy1
.Sine value is computed as
*psinVal = y0 + (fract * (y1 - y0))
.Fetch the value corresponding to
index
from cosine table toy0
and also value fromindex+1
toy1
.Cosine value is computed as
*pcosVal = y0 + (fract * (y1 - y0))
.
Functions
- RISCV_DSP_ATTRIBUTE void riscv_sin_cos_f32 (float32_t theta, float32_t *pSinVal, float32_t *pCosVal)
Floating-point sin_cos function.
- Parameters
theta – [in] input value in degrees
pSinVal – [out] points to processed sine output
pCosVal – [out] points to processed cosine output
- RISCV_DSP_ATTRIBUTE void riscv_sin_cos_q31 (q31_t theta, q31_t *pSinVal, q31_t *pCosVal)
Q31 sin_cos function.
The Q31 input value is in the range [-1 0.999999] and is mapped to a degree value in the range [-180 179].
- Parameters
theta – [in] scaled input value in degrees
pSinVal – [out] points to processed sine output
pCosVal – [out] points to processed cosine output