/* Fast approximation to the trigonometric cosine function for Q31 data.  */
q31_t arm_cos_q31(q31_t x)
/* Fast approximation to the trigonometric cosine function for Q31 data.  */
q31_t arm_cos_q31(q31_t x)
{
  q31_t cosVal;
  int32_t index;
  q31_t a, b;
  q31_t fract;
  x = (uint32_t)x + 0x20000000;
  if (x < 0)
  {
      x = (uint32_t)x + 0x80000000;
  }
  index = (uint32_t)x >> FAST_MATH_Q31_SHIFT;
  fract = (x - (index << FAST_MATH_Q31_SHIFT)) << 9;
  a = sinTable_q31[index];
  b = sinTable_q31[index+1];
  cosVal = (q63_t)(0x80000000-fract)*a >> 32;
  cosVal = (q31_t)((((q63_t)cosVal << 32) + ((q63_t)fract*b)) >> 32);
  return cosVal << 1;
}