www.jupiter-ace.co.uk

Previous Page > Listings Index > Ace SIN wave generator.


Ace SIN wave generator listing from Personal Computing World March 1984
Personal Computing World March 1984 page 318
PROGRAMS

Ace Sine Wave Generator
by M Stewart
'Sine Wave Generator' is a utility for the Jupiter Ace. The word SIN calculates successive values of sine and cosine in order to generate a sine wave. This should run on any Forth system, while the demonstration program (defined as DEMO) is specific to the Ace.
The idea for the definitions came from the article 'Accurate Sine-wave oscillator' published in Wireless World, June 1981. The author's definitions use a more general form of the equations published in the article, namely:

sin(n+1) = sin(n) + (1/m)cos(n) and
cos(n+1) = cos(n) – (1/m)sin(n+1)
where m is the value supplied by the user.
The word SIN uses the top three numbers on the stack to calculate the next members of the series, replacing the top of the stack with the next sine and the second to top with the next cosine. This gives the equation SIN(m,cos(n), sin(n) –m, cos(n+1),sin(n +1)).
If m is a large value, the starting value should be correspondingly high; and the higher the starting value, the more accurate the sine-wave.

: SIN
 ( m,cos(n),sin(n) - m,cos(n+1),sin(n+1))
 3 PICK 3 PICK SWAP / +
 SWAP 3 PICK 3 PICK
 SWAP / - SWAP
;
: DEMO
 ( plot a sine-wave on screen using SIN)
 INVIS CLS 4 20 0
 ( set m=4,cos(0)=20,sin(0)=0)
 63 0
 DO
  DUP 20 +
  ( set zero 20 pixels up)
  I SWAP 1 PLOT
  ( PLOT point at I,sin(I))
  SIN
  ( calculate next point)
 LOOP
;
The choice of cos(0)=20 and sin(0)=0 ensures that the maximum and
minimum values taken by the sine series are +20 and -20 respectively
The choice of m; gives approximately 2½ waves which fit on the
screen well.
These definitions were tried and tested on an unexpanded Jupiter Ace.
screen shot