This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Look up Table for XC164CS

hello everyone,

I just want to know if someone has any idea about look up table technique for sine or cosine function using keil simulator. I need to implement it in to my progam. I just want some basic idea. or if someone has good material then let me know.

I am using fixed point dsp Xc164Cs

thank you
Vivek

Parents
  • Actually, with a bit of extra work, 45 degrees is enough because of the symmetry between x and y :)

    Anyway, if you select 91 entries between 0 and 90 degrees with each value scaled * 16384, you will get the following results:

    If you do a direct lookup, truncating the angle to a whole degree, your worst error would be 0.0175.

    If your angle is in 0.01 degree steps, and you do linear interpolation between two entries, i.e.

    prox = ((100 - frac) * lut[angle] + (frac * lut[angle+1])) / (100 * 16384.);
    


    then your greatest error would be about 0.000097. That is 10 times your requirement.

    Without knowing the resolution of your angles and the real importance of your precision, I don't know if it would be advisable to create a larger LUT.

Reply
  • Actually, with a bit of extra work, 45 degrees is enough because of the symmetry between x and y :)

    Anyway, if you select 91 entries between 0 and 90 degrees with each value scaled * 16384, you will get the following results:

    If you do a direct lookup, truncating the angle to a whole degree, your worst error would be 0.0175.

    If your angle is in 0.01 degree steps, and you do linear interpolation between two entries, i.e.

    prox = ((100 - frac) * lut[angle] + (frac * lut[angle+1])) / (100 * 16384.);
    


    then your greatest error would be about 0.000097. That is 10 times your requirement.

    Without knowing the resolution of your angles and the real importance of your precision, I don't know if it would be advisable to create a larger LUT.

Children
  • Just a note - if you do need fractional angles, then it is better to make that scaling factor 2^n. Using angle steps 1/2, 1/4, 1/8, ... degrees allows you to use shift instead of division.

  • hi

    Well you are right. I need accuracy about 2 decimal after the point. Did anyone have idea about how to implement?

    this table is for optimization of speed. So i think i need to look pure lookup table for cosine function.

  • What do you mean by "Need accuracy about 2 decimal after the point"?

    Do you have an angle in degrees and the angle having two decimals, i.e. 0.00 to 359.99 degrees?

    Or is your requirements that the answer from the sin lookup must be -1.00 to 1.00 with a maximum error of +/- 0.005?

    I not only have an idea, I also suggested a specific solution. If you want maximum speed, i.e. single lookup without interpolation, you need a denser LUT than I suggested.

    If you use linear interpolation, you can decrease the density of the LUT and for example store a lookup value for every 5 degrees.

  • Yes:

    You can easily use a program such as Excel to generate the necessary values, then simply copy-and-paste them into a 'C' source file.
    Job done!

    Remember, too, that the sin & cos data are the same - you just need to apply the appropriate offset to the input...

  • hi

    My requirement is the sine angle is in degrees i.e. 0.00 degree to 359.99 degree

  • Time to implement. Generate a table with the sin() value between 0, 5, 10, ... 90 degrees scaled with 16384. In total 19 entries.

    Write code to detect what quadrant you are in - needed for adjusting the sign of the result.

    Convert your angle to a value between 0 and 90 degrees (taking into account negative angles or angles above 360 degrees).

    Split angle into an integer part (selects the first entry of the LUT) and a fractional part.

    Use the example source line I showed to perform a linear interpolation.

    Return result (but remember that it is scaled by a factor 16384).

    But as I mentioned, using integer algorithms, it is a bit bad to having 0.01 degree resolution to the angle. It is better to have 1/128 degree steps, letting the angle [0..369) be represented by an integer 0..46079, i.e. 128*0 .. 128*360-1.