added fixed-point CORDIC atan2

This commit is contained in:
Ahmet Inan 2019-02-13 02:36:39 +01:00
commit a4c31b1783
3 changed files with 112 additions and 0 deletions

33
tests/cordic_test.cc Normal file
View file

@ -0,0 +1,33 @@
/*
Test for the CORDIC atan2 function
Copyright 2019 Ahmet Inan <inan@aicodix.de>
*/
#include <cassert>
#include <iostream>
#include <cmath>
#include "unit_circle.hh"
#include "cordic.hh"
#include "const.hh"
template <typename TYPE>
void test()
{
const int N = 1 << (8*sizeof(TYPE));
for (int n = -N/2; n < N/2; ++n) {
TYPE x = nearbyint((N/2-1) * DSP::UnitCircle<double>::cos(n, N));
TYPE y = nearbyint((N/2-1) * DSP::UnitCircle<double>::sin(n, N));
TYPE a = DSP::CORDIC<TYPE>::atan2(y, x);
assert(abs(a-n) <= 1);
}
}
int main()
{
test<char>();
test<short>();
std::cerr << "CORDIC atan2 test passed!" << std::endl;
return 0;
}