Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. static q15_t my_sin_q15( q31_t x)
  2. {
  3. /* Calculate the nearest index */
  4. int32_t index = (uint32_t)x >> FAST_MATH_Q31_SHIFT;
  5.  
  6. /* Calculation of fractional value */
  7. q15_t fract = (x - (index << FAST_MATH_Q31_SHIFT)) >> 7;
  8.  
  9. /* Read two nearest values of input value from the sin table */
  10. q15_t a = my_sinTable_q15[index];
  11. q15_t b = my_sinTable_q15[index + 1];
  12.  
  13. /* Linear interpolation process */
  14. q31_t sin = (q31_t)((0x8000 - fract) * a) + ((q31_t)fract * b);
  15.  
  16. return sin >> 15;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement