Thursday, 5 September 2013

CORDIC for square roots

CORDIC for square roots

I have been looking at the CORDIC algorithm in hyperbolic rotation mode to
find the square root of a variable. I am unsure what my initial variables
should be (x0, y0, z0) to find the square root. I have read some papers,
citing that to find the sqrt(a), initial values should be set to a+1,a-1,0
for x0,y0,and z0 respectively. Others says it should be a+0.25,a-0.25,0. I
am very confused by this
Can anyone help?
An = 0.8281594; // compensate for 3j+1 repeats
int u = -1;
double x = 25+1;
double y = 25-1;
double z = 0;
int d = -1;
int n = 0;
while(n != 30 ){
double xn = x;
double yn = y;
double zn = z;
if(y < 0){
d = 1;
}
else
{
d = -1;
}
z = zn - d * atanh(pow(2.0,-1*n));
x = xn - u*d * pow(2.0,-1*n)*yn;
y = yn + d * pow(2.0,-1*n)*xn;
cout << "x: " << x << " y: " << y << " z: " << z << " d: " << d << endl;
if(n == 4)
{
double xn = x;
double yn = y;
double zn = z;
if(y < 0){
d = 1;
}
else
{
d = -1;
}
z = zn - d * atanh(pow(2.0,-1*n));
x = xn - u*d * pow(2.0,-1*n)*yn;
y = yn + d * pow(2.0,-1*n)*xn;
cout << "x: " << x << " y: " << y << " z: " << z << " d: " << d <<
endl;
}
if(n == 13)
{
double xn = x;
double yn = y;
double zn = z;
if(y < 0){
d = 1;
}
else
{
d = -1;
}
z = zn - d * atanh(pow(2.0,-1*n));
x = xn - u*d * pow(2.0,-1*n)*yn;
y = yn + d * pow(2.0,-1*n)*xn;
cout << "x: " << x << " y: " << y << " z: " << z << " d: " << d <<
endl;
}
n++;
}
EDIT* Along with compensating for 3j+1 repeats, CORDIC requires to execute
the loop twice in instances such as n = 4,13,40, ... I have updated my
code to compensate for that, but it still does not work.

No comments:

Post a Comment