| |
Conrad
Registered: Nov 2006 Posts: 849 |
How easy is it to calculate sine tables from the bare bones in ML?
Hi!
I'd like to have a go at coding my own routine of calculating sine/cosine tables without use of the BASIC interpreters (pi, sin(), etc) and just use pure ML instead.
Can I ask, how easy (or how SMALL) is this to do? Do I need to do additional algorithms like factorial or are there KERNAL routines for that (if any)? Multiplication code is no problem as I've seen articles on those, I'm just thinking about the rest of math involved with sine calculation.
Thanx in advance. |
|
| |
enthusi
Registered: May 2004 Posts: 677 |
Im probably the wrong person to answer this :)
but you can easyly abuse the BASIC routines in ML as well. Just set up the FAC etc adresses and launch the routines.
OR if you want it really basic withou BASIC routines you can do the Taylor-approach
sin(x)=x-1/x^3+1/x^5 etc.
There probably smarter ways around though *g* |
| |
doynax Account closed
Registered: Oct 2004 Posts: 212 |
You can generate a sine wave iteratively easily enough. Basically you just massage the trigonometric product formula a bit..
sin(x - y) + sin(x + y) = 2 * sin x * cos y <=>
sin(x + y) = 2 * sin x * cos y - sin(x - y) Where 'y' is your step and x is the index being calculated. In other words we end up basing the next sine on the previous two, through a multiplication by a constant and a subtraction.k = 2 * cos d
sin[i + d] = sin[i] * k - sin[i - d] Now I guess if you apply a scaling/steps width such that the constant becomes a nice simple power-of-two then this could be implemented with less code then invoking the basic ROM functions.
Please note that it takes quite a bit of fixed-point precision to get decent values, and you may want to consider exploiting a bit of symmetry to generate the rest of the table from the first quadrant or so. |
| |
Skate
Registered: Jul 2003 Posts: 494 |
There are some 256b intros with source code which generates sine tables. Check this one for example.
Too(C)o(M)p(L)ex
Of course try to learn it, not copy & paste it.
|
| |
Radiant
Registered: Sep 2004 Posts: 639 |
To avoid nasty multiplications you could approximate a circle using an accelerating vector. I think it was Zed Yago who suggested this solution on IRC some time ago, and it sounds good enough for me. |
| |
Conrad
Registered: Nov 2006 Posts: 849 |
Thanks everyone for your help! I have a rough idea what to do now! :)
radiantx: what's an accelerating vector? Is it related to I/O registers or is a much more complex formula? Again, I could ask Yago myself :) |
| |
WVL
Registered: Mar 2002 Posts: 902 |
Quote: Thanks everyone for your help! I have a rough idea what to do now! :)
radiantx: what's an accelerating vector? Is it related to I/O registers or is a much more complex formula? Again, I could ask Yago myself :)
I guess yago meant that you can approximate a sine with 2 parabolas, and to calculate those you only need to have an acceleration (which matches the amplitude and 'length' of the sine you want.) |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
@Skate: Too bad it's some ugly sines that are generated that way. It's really just a couple of reverse parabolas, which is not the same as a real sine.
|
| |
Conrad
Registered: Nov 2006 Posts: 849 |
Ah, now I get ya, after looking up on parabolas ;).
Thanks again, all! .... off to code.
cruzer: that's okay, quick'n'dirty is all I need. |
| |
Shadow Account closed
Registered: Apr 2002 Posts: 355 |
Anyone have an example on how to access the BASIC routines from asm to generate a sine? Also how compact is such a routine, are we talking like 50 bytes or 500 bytes? |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Anything you come up with, plz write a small article about it and post it on codebase. Mkaytnku. |
... 22 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 | 4 - Next |