🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.dsp
Article #1714

Re: Sine-wave generator algorithms

#1714
From: Ge' Weijers
Date: Wed, 24 Apr 1991 17:38
58 lines
2284 bytes
dandb+@cs.cmu.edu (Dean Rubine) writes:

>In article <1750@tekig7.MAP.TEK.COM> gaulandm@tekig7.MAP.TEK.COM (Mike Gauland) writes:
>>I'm trying to implement a sine-wave generator using a DSP.  Anyone have
>>an especially quick algorithm they'd like to share?


>   I seem to recall from a standard graphics text that this method is
>slightly unstable: when used to draw circles it produces spirals.
>I'm not sure about this, but I seem to remember there was a simple fix,
>which unfortunately involved another multiply.

A standard CG trick to generate circle points is the "register saving" technique
originating from a programmer's mistake.

Rotating a point around the origin can be done by multiplying by a
rotation matrix:

                /  cos(phi)  -sin(phi)  \
[x' y'] = [x y] |                       |
		\  sin(phi)   cos(phi)  /

As an approximation for small angles you can use the matrix

    / 1       -phi \
    |              |
    \ phi       1  /

A program rotating the point:

   tmp = x + y * phi
   y = y - x * phi
   x = tmp

The mistake was:

   x = x + y * phi
   y = y - x * phi  (saving one scratch register)

This corresponds to the matrix

    / 1       -phi \
    |              |
    \ phi  1-phi^2 /

which has a determinant equal to 1. This algorithm draws an ellipse very close
to a circle. For further information see a CG book like
Graphics Gems, by A. Glassner.

I don't know whether this algorithm is stable, but you could restart it
after one full circle and use the X component as output.

Ge' Weijers
--
Ge' Weijers                                    Internet/UUCP: ge@sci.kun.nl
LCN Foundation
Reguliersstraat                                tel. +3180238130 (UTC+1,
6525 ED Nijmegen, the Netherlands               UTC+2 march/september
Technical Details
Message-ID: <3472@wn1.sci.kun.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uunet!mcsun!hp4nl!sci.kun.nl!ge
References: <1750@tekig7.MAP.TEK.COM> <1991Apr15.081550.26195@bernina.ethz.ch> <1991Apr24.050126.8668@cs.cmu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uunet!mcsun!hp4nl!sci.kun.nl!ge
From: ge@dbf.kun.nl (Ge' Weijers)
Newsgroups: comp.dsp
Subject: Re: Sine-wave generator algorithms
Message-ID: <3472@wn1.sci.kun.nl>
Date: 24 Apr 91 17:38:19 GMT
References: <1750@tekig7.MAP.TEK.COM> <1991Apr15.081550.26195@bernina.ethz.ch> <1991Apr24.050126.8668@cs.cmu.edu>
Sender: root@sci.kun.nl
Lines: 58