Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Implementation of sine cosine using LUT

Status
Not open for further replies.

gary36

Full Member level 4
Joined
Mar 31, 2018
Messages
208
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,806
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?
 

CORDIC is an algorithm for performing calculations. A LUT is simply that, a look-up 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.
 

Hi barry

I checked matlab and they implement LUT with interpolation. Can you educate me on this?
 

We can generate a look-up 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.
 

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.
 

In Matlab, the number of points for LUT is 32 only. How do they get the precision?
 

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.

Brian
 

We can generate a look-up table of sines from 0 to 45 degrees by starting with .7071 (sine of 45 deg), and taking equal proportions.

What you are suggesting is called linear extrapolation; look up tables may use actual values and can be more accurate.

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 ...
 

Hi,

@Brian:
Symmetry - 32 points in 45 degrees means (360/45)*32 = 256 points in total.
I know the "quarter wave" LUT implementation.... but quarter wave means 4 x 90°. How does the 45° table work?

@gary36:
How do they get the precision?
.
Sure you mean "precision"? Or do you ask about "resolution"?

Klaus
 

I know the "quarter wave" LUT implementation.... but quarter wave means 4 x 90°. How does the 45° table work?

Quarter wave is 90 degree, thus 32 points per 90 degree. 45 degree table makes no sense for sine LUT.

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.
 

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.
 

How does the 45° table work?

Using trigonometric identities.

For 90 >x >45, we use the formula

sin(90-x)=cos(x)=sqrt(1-sin^2(x))

Actually the sinus and cosinus tables are the same (one table does both the work).
 
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.
 

For angle less than 42 degrees from horizontal, multiply by ∏/180 to get sine within 10 percent error.

Right. A large part of the sine curve can be approximated by a straight line; see the graph below.

temp.png

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:

temp1.png
 
Using trigonometric identities.

For 90 >x >45, we use the formula

sin(90-x)=cos(x)=sqrt(1-sin^2(x))

Actually the sinus and cosinus tables are the same (one table does both the work).
Surely possible but rarely reasonable, neither for µC nor programmable logic implementation.
 

Surely possible but rarely reasonable, neither for µC nor programmable logic implementation.

You are right; the look up table has to be computed outside. Only the table has to be stored.

If you are using a 8-bit 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 non-critical work, a simple table of 16 (array of size 16 of unsigned bytes) may be more than sufficient.
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top