43 #define SIN_TAB_LEN 120
45 #define ABS(x) (x < 0 ? -x : x)
47 static const int8_t SIN_TAB[] = {
48 0,6,13,20,26,33,39,45,52,58,63,69,75,80,
49 85,90,95,99,103,107,110,114,116,119,121,
50 123,125,126,127,127,127,127,127,126,125,
51 123,121,119,116,114,110,107,103,99,95,90,
52 85,80,75,69,63,58,52,45,39,33,26,20,13,6,
53 0,-6,-13,-20,-26,-33,-39,-45,-52,-58,-63,
54 -69,-75,-80,-85,-90,-95,-99,-103,-107,-110,
55 -114,-116,-119,-121,-123,-125,-126,-127,-127,
56 -127,-127,-127,-126,-125,-123,-121,-119,-116,
57 -114,-110,-107,-103,-99,-95,-90,-85,-80,-75,
58 -69,-63,-58,-52,-45,-39,-33,-26,-20,-13,-6
62 static uint16_t bitrev(uint16_t j, uint16_t nu)
66 for (; nu > 0; nu--) {
67 k = (k << 1) + (j & 1);
75 static int16_t sinI(uint16_t angleMilli)
78 pos = (uint16_t) ((SIN_TAB_LEN * (uint32_t) angleMilli) / 1000);
79 return SIN_TAB[pos % SIN_TAB_LEN];
82 static int16_t cosI(uint16_t angleMilli)
84 return sinI(angleMilli + 250);
87 static uint16_t ilog2(uint16_t val)
114 ifft(int16_t xre[], int16_t xim[], uint16_t n)
120 int32_t c, s, tr, ti;
126 for (i = 0; i < n; i++)
129 for (l = 1; l <= nu; l++) {
130 for (k = 0; k < n; k += n2) {
131 for (i = 1; i <= n2; i++) {
132 p = bitrev(k >> nu1, nu);
133 c = cosI((1000 * p) / n);
134 s = sinI((1000 * p) / n);
136 tr = ((xre[k + n2] * c + xim[k + n2] * s) >> RESOLUTION);
137 ti = ((xim[k + n2] * c - xre[k + n2] * s) >> RESOLUTION);
139 xre[k + n2] = xre[k] - tr;
140 xim[k + n2] = xim[k] - ti;
150 for (k = 0; k < n; k++) {
165 for (i = 0, n2 = n / 2; i < n2; i++) {
166 xre[i] = (ABS(xre[i]) + ABS(xim[i]));