Error in ROM Sin table???.....No there is no error....it is my mistake
SamMishal
Posts: 468
Hi All,
I downloaded the Sin table values from the ROM and put them into an excel spread sheet and compared the values to calculated values.
I am sure I am wrong....but...I found that in many places there is a LARGE error......where am I going wrong?
Here is an excerpt from the spread sheet
I noticed the errors get larger towards the middle of the table. At the beginning and the end there was only an error of 1 or 2.
See the attached zip file that contains an .XLS file for a full table.
If you are wondering how I got the values, I used a RobotBASIC program to read the data from the Propeller running a SPIN program.
See the attached programs below.
The RobotBASIC program even plots the values and the Plot is perfect looking. Also the RB program puts the values on the Clipboard
which I then used to paste into the excel sheet in the "Spin Table Sin()" column as you see above.
In the·spread sheet·the "Calculated Sin()" uses the formula
·· · =ROUND(SIN(Angle)*65535,0)
this gets the normal Sin() which of course ranges from 0 to 1 (for angles 0 to 90) and then multiplies it by 65535 and rounds it to
get an integer value ranging from 0 to 65535 (i.e. 16-bit integer) as is given in the ROM table.
(I could have used RobotBASIC to do all these calcs but I wanted people to see the data without having
·to run or download RB and most people have Excel)
So my questions are:
·· - Why are the values from the ROM so far off from the calculated values?
········· I know 18 is not much but that happens to be 0.04% in some places....not much really
········· But why couldn't the ROM data have been made more accurate?
·· - Am I missing something obvious?
Regards
Samuel
Post Edited (SamMishal) : 9/14/2009 10:25:54 AM GMT
I downloaded the Sin table values from the ROM and put them into an excel spread sheet and compared the values to calculated values.
I am sure I am wrong....but...I found that in many places there is a LARGE error......where am I going wrong?
Here is an excerpt from the spread sheet
[img]http://forums.parallax.com/attachment.php?attachmentid=74234[/img] [img]http://forums.parallax.com/attachment.php?attachmentid=74235[/img]
I noticed the errors get larger towards the middle of the table. At the beginning and the end there was only an error of 1 or 2.
See the attached zip file that contains an .XLS file for a full table.
If you are wondering how I got the values, I used a RobotBASIC program to read the data from the Propeller running a SPIN program.
See the attached programs below.
The RobotBASIC program even plots the values and the Plot is perfect looking. Also the RB program puts the values on the Clipboard
which I then used to paste into the excel sheet in the "Spin Table Sin()" column as you see above.
In the·spread sheet·the "Calculated Sin()" uses the formula
·· · =ROUND(SIN(Angle)*65535,0)
this gets the normal Sin() which of course ranges from 0 to 1 (for angles 0 to 90) and then multiplies it by 65535 and rounds it to
get an integer value ranging from 0 to 65535 (i.e. 16-bit integer) as is given in the ROM table.
(I could have used RobotBASIC to do all these calcs but I wanted people to see the data without having
·to run or download RB and most people have Excel)
So my questions are:
·· - Why are the values from the ROM so far off from the calculated values?
········· I know 18 is not much but that happens to be 0.04% in some places....not much really
········· But why couldn't the ROM data have been made more accurate?
·· - Am I missing something obvious?
Regards
Samuel
Post Edited (SamMishal) : 9/14/2009 10:25:54 AM GMT
Comments
I did, however, discover that the table is normalized to 65535 rather than 65536. I had assumed the latter (and it still makes more sense to me).
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 9/14/2009 8:52:55 AM GMT
I have discovered the error.......it is because I am using excel.....had I used RB to calculate the
values I would not have had the error.....I did the calculations using RB and there was no error.
I used the formula
and that printed no lines at all which means that all calculated N were equal to a[noparse][[/noparse]i] (data from table).
So·I went through the Excel formulas and found that the problem is in the way I am generating
the data in the Angles column....which actually makes sense once I thought about it....
I am generating each angle in each row as the sum of the angle in the row above it and Pi()/4096 (seems logical...no?).
This looks like it is OK initially....but that means each error in the row above is accumulated in the row below
and thus the problem......
When I changed the Angles column to calculate the angle from a counter as I did using RB then it was
OK and there was no errors too.
I knew there was something wrong......and it is due to my inability to use Excel properly.....
I should have stuck to RobotBASIC in the first place.........
But it is interesting how what seemed as a logical thing to do is actually quite wrong when considered in details...
Anyway this was an interesting exercise....I was trying to understand the ROM sin and log tables
on my way to figure out how to use them to generate DTMF tones using PWM techniques.
Has anyone done this....is there an OBEX object for a summing-multichannel sinewave generator?
I looked and I cannot see any???
Regards
Samuel
·