CORDIC Conundrum


i in process of playing alternate ways of generating elementary functions (eg ln, log, sin, cos, tan, etc), using methods such modified taylor series , in case cordic. trying couple digits of precision on functions provided in standard arduino development environment without breaking cpu cycle bank account.

the internet has large number of references way cordic works of provide interesting side-tracks origin of method (thanks jack volder) , various calculator implementations. works have had number of calculators produce quite satisfactory elementary functions , in probability using cordic of 1 sort or another.

however practical implementations following 2 papers useful:
the first dr dobbs: http://www.drdobbs.com/microcontrollers-cordic-methods/184404244
and referenced same article: http://www.siue.edu/~gengel/pdf/cordic.pdf

i decided implement log10(x) function using 64 bit fixed point implementation 32 bits right of binary point , 32 bits left giving combination of decent precision , reasonable range. 8 bytes bit of cpu load interested in how performed.

the algorithm in form of pseudo-code used articles is:

log10(x){
 z = 0;
 for ( i=1;i=<b;i++ ){
    if (x > 1)
       x = x - x*2^(-i);
       z = z - log10(1-2^(-i));
     else
       x = x + x*2^(-i);
       z = z - log10(1+2^(-i));
 }
 return(z)
}

to make work requires series of constants article explains adequately. in case used excel generate these constants. see attached log_10_constants.xls tends make final comparison circular constants generated excel , checked excel.

the code attached. please forgive odd diagnostic , commented out prints in code. algorithm print out 32.32 number isn't ideal either not bad job. limited precision of floats kind of defeats idea of more digits problem later. works enough testing first step.

the result interesting , can seen in attachment log_10_examples.xls.the graph shows performance on range approximately 0.5 3.5 inside cordic range, native arduino , excel log10 comparison.

one of issues of these approximations knowing error is. took values of cordic algorithm, standard arduino log10 , excel log10 , plotted them , error measured excel log10. cordic shows significant patches of error wasn't expecting.


i have highlighted cordic errors red circles on graph quite large on small ranges result excellent elsewhere. arduino , excel log10 excellently matched cordic has apparent errors.

i have tried cordic algorithm  manually , errors same. comes down algorithm not "switching" >1 , <= 1 should narrow down right answer. such there nothing wrong algorithm. cordic not work expected precision in these ranges. algorithm such defect not useful.

since range modification required anyway, .5 3.5 restrictive , require range modified possibility avoid error-prone areas. there might alternative or better that.

any ideas how fix or calculators avoid problem???


note in order upload files have changed them .doc. if want @ them need download , change extension .xlsx.

its job post files in sensible format, not make of jump through hoops...
save .csv?


Arduino Forum > Using Arduino > Programming Questions > CORDIC Conundrum


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'