arctan_t

allocate 16bit table with arctan shape in SDRAM memory, -128.00 .. 127.99
Author: Sputnki
License: BSD
Github: sptnk/table/arctan_t.axo

Inlets

None

Outlets

None

Attributes

combo size

spinner value

Declaration
static const uint32_t LENGTHPOW = (attr_size);
static const uint32_t LENGTH = (1 << attr_size);
static const uint32_t LENGTHMASK = ((1 << attr_size) - 1);
static const uint32_t BITS = 16;
static const uint32_t GAIN = 12;
int16_t *array;
Init
static int16_t _array[attr_poly][LENGTH] __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];
{
  int i;
  for (i = 0; i < LENGTH; i++)
    array[i] = 0;
}

int i;
double d;
double x;
double range;

float a = -attr_value /
          4; // these two parameters will serve as a range for the function
float b = -a;

for (i = 0; i < LENGTH; i++) {
  x = i;
  x = (x * (b - a) / LENGTH + a); // bonding the domain from [a,b] to [0,length]

  if (x <= -2) {
    x = x + 2;
    d = -1.10714872 + x / 5 + (x * x) * 2 / 25 + (x * x * x) * 11 / 375 +
        (x * x * x * x) * 6 / 625 + (x * x * x * x * x) * 41 / 15625;
  } else if (x >= 2) {
    x = x - 2;
    d = 1.10714872 + x / 5 - (x * x) * 2 / 25 + (x * x * x) * 11 / 375 -
        (x * x * x * x) * 6 / 625 + (x * x * x * x * x) * 41 / 15625;
  } else if ((x <= -1) && (x > -2)) {
    x = x + 1;
    d = -3.1415 / 4 + x / 2 + (x * x) / 4 + (x * x * x) / 12 -
        (x * x * x * x * x) / 40;
  } else if ((x >= 1) && (x < 2)) {
    x = x - 1;
    d = 3.1415 / 4 + x / 2 - (x * x) / 4 + (x * x * x) / 12 -
        (x * x * x * x * x) / 40;
  } else
    d = x - (x * x * x) / 3 + (x * x * x * x * x) / 5 -
        (x * x * x * x * x * x * x) / 7 +
        (x * x * x * x * x * x * x * x * x) / 9 -
        (x * x * x * x * x * x * x * x * x * x * x) /
            11; //+(x*x*x*x*x*x*x*x*x*x*x*x*x)/13-(x*x*x*x*x*x*x*x*x*x*x*x*x*x*x)/15;//+(x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x)/17-(x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x)/19;
                ////actual taylor polynomial
  if (i == 0)
    range = -d;
  d = d * 32768 /
      range; // bonding the codomain from [-pi/2,pi/2] to [-2^15,2^15]
  array[i] = d;
}

Privacy

© 2024 Zrna Research