+ Post New Thread
Results 1 to 16 of 16

24th November 2019, 13:49 #1
 Join Date
 Mar 2018
 Posts
 102
 Helped
 0 / 0
 Points
 862
 Level
 6
Implementation of sine cosine using LUT
I was referring to link https://in.mathworks.com/help/simulink/slref/sine.html that describes the generation of sine through LUT exploiting quarter wave symmetry. I wanted to understand the concept and also how it is different from Cordic?. Matlab always recommends LUT based sine/cos over cordic for fixed point implementation. Why is so?

Advertisement

25th November 2019, 01:36 #2
 Join Date
 Mar 2005
 Location
 California, USA
 Posts
 4,726
 Helped
 1048 / 1048
 Points
 24,650
 Level
 38
Re: Implementation of sine cosine using LUT
CORDIC is an algorithm for performing calculations. A LUT is simply that, a lookup table: phase in, amplitude out. The CORDIC implementation takes several cycles to produce an output; a LUT produces an output in a single cycle. I suspect MATLAB recommends a LUT based approach because it’s faster.

25th November 2019, 02:25 #3
 Join Date
 Mar 2018
 Posts
 102
 Helped
 0 / 0
 Points
 862
 Level
 6
Re: Implementation of sine cosine using LUT
Hi barry
I checked matlab and they implement LUT with interpolation. Can you educate me on this?

25th November 2019, 05:24 #4
 Join Date
 Apr 2011
 Location
 Minneapolis, Minnesota, USA
 Posts
 13,052
 Helped
 2598 / 2598
 Points
 53,441
 Level
 56
Re: Implementation of sine cosine using LUT
We can generate a lookup table of sines from 0 to 45 degrees by starting with .7071 (sine of 45 deg), and taking equal proportions.
Thus for 1 degree we take one 45th of .7071. This gives us .0157 which is 10 percent off from the true value (.017). Error increases below 1 degree.
Values for the entire 360 degree circle are generated in like manner, by taking proportion of distance from 45 or 135 or 225 or 315.
Doubtless Matlab and Cordic generate their LUT based on a larger number of accurate reference points.

25th November 2019, 07:00 #5
 Join Date
 Mar 2005
 Location
 California, USA
 Posts
 4,726
 Helped
 1048 / 1048
 Points
 24,650
 Level
 38
Re: Implementation of sine cosine using LUT
You’ll have to read the Matlab documentation.But, if I had to guess, I would assume they simplify take two adjacent points from the LUT and interpolate between them.

25th November 2019, 07:36 #6
 Join Date
 Mar 2018
 Posts
 102
 Helped
 0 / 0
 Points
 862
 Level
 6
Re: Implementation of sine cosine using LUT
In Matlab, the number of points for LUT is 32 only. How do they get the precision?

25th November 2019, 10:07 #7
Awards:
 Join Date
 Jul 2009
 Location
 Aberdyfi, West Wales, UK
 Posts
 13,551
 Helped
 4514 / 4514
 Points
 82,552
 Level
 70
Re: Implementation of sine cosine using LUT
Symmetry  32 points in 45 degrees means (360/45)*32 = 256 points in total. An average of a little over 1 degree per point but also a convenient LUT size for software/hardware to use.
BrianPLEASE  no friends requests or private emails, I simply don't have time to reply to them all.
It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

Advertisement

25th November 2019, 10:43 #8
 Join Date
 Nov 2012
 Posts
 3,267
 Helped
 815 / 815
 Points
 18,428
 Level
 32
Re: Implementation of sine cosine using LUT
We can generate a lookup table of sines from 0 to 45 degrees by starting with .7071 (sine of 45 deg), and taking equal proportions.
In good old days, we had books that had many kind of tables: log, trigonometric functions, statistical values and many had random numbers. They are the original look up tables.
The series expansion formula for sin(x) = x  x^3/3! + x^5/5!  x^7/7! + ...
If you take first three terms, you can get better accuracy ...

25th November 2019, 12:02 #9
Awards:
 Join Date
 Apr 2014
 Posts
 16,261
 Helped
 3688 / 3688
 Points
 80,117
 Level
 69
Re: Implementation of sine cosine using LUT
Hi,
@Brian:
Symmetry  32 points in 45 degrees means (360/45)*32 = 256 points in total.
@gary36:
How do they get the precision?
Sure you mean "precision"? Or do you ask about "resolution"?
KlausPlease don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

25th November 2019, 12:22 #10
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 46,001
 Helped
 13989 / 13989
 Points
 263,643
 Level
 100
Re: Implementation of sine cosine using LUT
I know the "quarter wave" LUT implementation.... but quarter wave means 4 x 90°. How does the 45° table work?
Interpolation error with 32 point table is already very small. There's no application mentioned in this thread, thus the requirements are unknown.
Series expansion is another possible method, but involving higher calculation effort. LUT with or even without interpolation is most suitable for a large range of microcontroller and programmable logic applications.

25th November 2019, 22:19 #11
Awards:
 Join Date
 Jul 2009
 Location
 Aberdyfi, West Wales, UK
 Posts
 13,551
 Helped
 4514 / 4514
 Points
 82,552
 Level
 70
Re: Implementation of sine cosine using LUT
You are quite right to correct me FvM  put my mistakes down to old age.
They say your memory goes first ...... and I can't remember what comes second.
Brian.PLEASE  no friends requests or private emails, I simply don't have time to reply to them all.
It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

Advertisement

26th November 2019, 02:18 #12
 Join Date
 Nov 2012
 Posts
 3,267
 Helped
 815 / 815
 Points
 18,428
 Level
 32
Re: Implementation of sine cosine using LUT
How does the 45° table work?
For 90 >x >45, we use the formula
sin(90x)=cos(x)=sqrt(1sin^2(x))
Actually the sinus and cosinus tables are the same (one table does both the work).
1 members found this post helpful.

26th November 2019, 03:26 #13
 Join Date
 Apr 2011
 Location
 Minneapolis, Minnesota, USA
 Posts
 13,052
 Helped
 2598 / 2598
 Points
 53,441
 Level
 56
Re: Implementation of sine cosine using LUT
For angle less than 42 degrees from horizontal, multiply by ∏/180 to get sine within 10 percent error.
Thus 30 degrees x ∏/180 = .5236. Correct value is .5.

26th November 2019, 04:44 #14
 Join Date
 Nov 2012
 Posts
 3,267
 Helped
 815 / 815
 Points
 18,428
 Level
 32
Re: Implementation of sine cosine using LUT
For angle less than 42 degrees from horizontal, multiply by ∏/180 to get sine within 10 percent error.
As sin(x) is always within +/1, 10% accuracy means only one decimal significant digit. For most purposes, this will be insufficient.
   Updated   
Just two terms, you get a much better result: with three terms, you can see the significant improvement:
1 members found this post helpful.

26th November 2019, 15:34 #15
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 46,001
 Helped
 13989 / 13989
 Points
 263,643
 Level
 100
Re: Implementation of sine cosine using LUT
Using trigonometric identities.
For 90 >x >45, we use the formula
sin(90x)=cos(x)=sqrt(1sin^2(x))
Actually the sinus and cosinus tables are the same (one table does both the work).

26th November 2019, 16:52 #16
 Join Date
 Nov 2012
 Posts
 3,267
 Helped
 815 / 815
 Points
 18,428
 Level
 32
Re: Implementation of sine cosine using LUT
Surely possible but rarely reasonable, neither for µC nor programmable logic implementation.
If you are using a 8bit interger, 1 to +1 need to be mapped into 0 to 255.You will perhaps get an accuracy of 1% or better.
If you are using quarter wave, (i.e., 0 to 90 deg), you can perhaps use a table of 16 or 32 values. With a size of 32 values, your each angle will have a resolution of 90/32 (say about 3 degree).
For intermediate values, a simple linear interpolation will be sufficiently accurate; this is the most common practice.
For greater accuracy, you need to have 16 bit interger calculations and have 64 or 128 size table. But that depends on the application.
Once the table is programmed into the microprocessor, there will be no additional computational burden involved (perhaps excepting some small interpolations).
These are essentially academic discussions because the table has to be made externally only once and there are standard routines available for these trigonometric functions.
For noncritical work, a simple table of 16 (array of size 16 of unsigned bytes) may be more than sufficient.
1 members found this post helpful.
+ Post New Thread
Please login