What is in the Sine table?
ksltd
Posts: 163
I can find no information in the manual about the format of the 16-bit unsigned values in the sine table. I'm presuming they're fixed point values, but where's the implied binary point? Is the data 1.15?
Comments
http://www.parallax.com/downloads/propeller-manual
Thanks for your response. If you read my post carefully, you'll see that it says "I can find no information in the manual about the format of the 16-bit unsigned values in the sine table". That includes the samples in Appendix B.
Neither the text nor the code snippet indicate the format of the data in the ROM and the code snippet doesn't indicate the format of the data that it returns.
I'm sure you're trying to be helpful - but there's just nothing there.
Perhaps someone who knows?
If you can read Forth, here are my fixed point trig functions:
Sine Table
The sine table provides 2,049 unsigned 16-bit sine samples spanning from 0° to 90°,
inclusively (0.0439° resolution). Sine values for all other quadrants covering > 90° to < 360°
can be calculated from simple transformations on this single-quadrant sine table. The sine
table can be used for calculations related to angular phenomena.
See Appendix B: Math Samples and Function Tables on page 380 for more information.
Th appendix says the same and has an example of how to extend that too the full 360 degrees.
I'm going to assume the value at position 0 in the table is 00000000_00000000 seeing as sine(0) = 1.
I'm going to assume the value at position 2048 is 11111111_11111111 as that is the biggest unsigned 16 bit value one can have. It must represent 1.0 as sine(90) = 1.
So effectively the binary point is in front of that 0.11111111_11111111
The right most bit, the LSB, therefore being 90 / 2048 = 0.0439 degrees as stated in the manual.
The procedure presented in the index will get you the full circle.
I might be wrong but a quick Spin program would verify it. All the info required seems to be there.
Think of it as the values in the table as 16 bit unsigned integers. The output values represent fractional sine values ranging from 0 to 65535/65536 for values in the first quadrant. Effectively fixed point radix to the left of the 16th bit.
Here is a Spin program that prints out values at intervals around the full circle. The FullSine method takes an angle\ from 0 to 8191 and returns the sine of that angle as an integer from -65535 to +65535. Those values represent sines from -65535/65536 to +65535/65536. The program also converts the result into decimal, 4 digits precision.
It's definitely not indexed by radians, it's indexed by 1/2048ths of degrees. That much is explained in the manual.
Heater,
If all the information were there, believe me, I'd not have asked the question. And, I'd imagine that your explanation wouldn't be couched in two assumptions and the ubiquitous "I might be wrong".
Tracy,
So you're saying values in the table are in 0.16 fixed point format and your program takes Angles in degrees with the LSB equal to 90/2048 degrees and only works for angles in the range 0..360. Got it. Thanks.
http://forums.parallax.com/showthread.php/156866-Question-for-Chip-re-ROM-code
Radians or degrees it makes on difference.
What we have here is 2049 numbers representing the value of the sine function over one quarter of a full rotation.
What the manual clearly states is "...2,049 unsigned 16-bit sine samples spanning from 0° to 90°,
inclusively (0.0439° resolution)".
One could just as well say "...2,049 unsigned 16-bit sine samples spanning from 0 to PI/2 radians,
inclusively (0.0007666 radian resolution)".
Same thing.
We see that all the information is indeed in the manual.
Yes I'm fond of the "I might me wrong". Perhaps we find that the manual has errors or omissions on this point, would not be the first time. Perhaps the ROM in the Propeller is wrong, unlikely. Perhaps my own understanding or arithmetic has slipped up, that certainly would not be a first.
Finally given the information in the manual, which turns out to be correct and complete, it would only take a five minute experiment to dump out the values and check ones understanding.
I said binary radian, not radian. It's a common technique for representing trig functions with integers. See this article:
http://en.wikipedia.org/wiki/Binary_scaling
Sort of. Implementation of trig functions always involves clever folding, scaling and range reduction. My snippet of a program does the calculation in brads (as Martin_H said, binary radians) with the full circle broken into 8192 segments. It is easy enough to convert that to units of degrees or radians if that is what is required. Range extension too is easy, if required. The 11 bit precision going in is less than the 16 bit precision coming out, so the 0.16 fixed point format is a bit deceptive unless you also implement interpolation, as is done in the floating point packages. I can see it as 0.16 fixed point, but I think of it first as a dimensionless ratio of integers apart from any particular number system or scale factor.
Erna A poet as always!
Here's an object I wrote that uses the Sin table in Spin.
Most functions take a radius argument. The radius argument is necessary to scale the sin value output to be an integer number. Otherwise a value of -1 to 1 would be returned. Generally, just call the functions with the radius value set to something large. Like 100 or 1000.
2049 sounds like an odd value to me. Is it a typo?
Sandy
Imagine you wanted to plot a graph of some function, y = f(x), over the range x >= 0, x >= 10. And you only had values of y for integer values of x, x = 0,1,2,3,4,5,6,7,8,9,10
See, we have 11 points to plot not just 10. This is a "fence post" problem. There is one more fence post that the number of gaps between the posts to cover a particular length of fence.
So it goes with the table of sin(x) in the PROM.
I think you're right.
I got bored and wrote a little program to dump the contents of the sine table. The results are included as Sine Table Dump.txt in the archive. I had to do in in three goes because otherwise the results would be clipped in the debug window. The debug window contents were copied into Sine Table Dump.txt after each program run.
After word number 2048 ( address F000 to F001 ) the numbers are obviously wrong.
Sandy
The sine table addresses are from $E000 to $F001 and the booter/interpreter addresses are $F002 to $FFFF.
See page 31 in the Propeller manual (Memory map)
Yes, this is indeed correct and a special accommodation of 2049 entries in order to make the use of binary radians deploy easily. At some point, the use of the table requires one to learn what a 'binary radian' is and how to use it with binary maths. The Table is intended to allow optimal programing in binary maths, not floating point or fixed point.
Search on BRADs...
http://en.wikipedia.org/wiki/Binary_scaling
Which works perfectly. I just cut and pasted two PUBs (Sin and Cos) and two PRI helper methods (one scales the radius and one does the actual lookup) and LoAndBehold: an analog clock!