Current Article  

Generating trigonometric tables

Tablestrigonometric functionsuseful innumberareas. Beforeexistencefast pocket calculators, trigonometric tables were essentialnavigation, scienceengineering. The calculationmathematical tables was an important areastudy, which led todevelopment offirst mechanical computing devices.

Modern computerspocket calculators now generate trigonometric function values on demand, using special librariesmathematical code. Often, these libraries use pre-calculated tables internally,computerequired value by using an appropriate interpolation method.

Interpolationsimple look-up tablestrigonometric functionsstill usedcomputer graphics, where accurate calculationseither not needed, or cannot be made fast enough.

Another important applicationtrigonometric tablesgeneration schemes isfast Fourier transform (FFT) algorithms, wheresame trigonometric function values (called twiddle factors) must be evaluated many times ingiven transform, especially incommon case where many transforms ofsame sizecomputed. In this case, calling generic library routines every timeunacceptably slow. One option iscalllibrary routines once,build uptablethose trigonometric values that will be needed, but this requires significant memorystoretable. The other possiblity, sinceregular sequencevaluesrequired, isuserecurrence formulacomputetrigonometric values onfly. Significant research has been devotedfinding accurate, stable recurrence schemesorderpreserveaccuracy ofFFT (whichvery sensitivetrigonometric errors).

Tablecontents
1 A quick, but inaccurate, approximation
2 A better, but still imperfect, recurrence formula
3 References

A quick, but inaccurate, approximation

A quick, but inaccurate, algorithmcalculatingtableN approximations snsin(2&pin/N)cncos(2πn/N) is:

s0 = 0
c0 = 1
sn+1 = sn + d × cn
cn+1 = cn - d × sn
for n = 0,...,N-1, where d = 2π/N.

ThissimplyEuler methodintegratingdifferential equation:

with initial conditions s(0)=0c(0)=1, whose analytical solutions = sin(t)c = cos(t).

Unfortunately, thisnotuseful algorithmgenerating sine tables becausehassignificant error, proportional1/N.

For example,N = 256maximum error insine values~0.061 (s202 = -1.0368 instead-0.9757). For N = 1024,maximum error insine values~0.015 (s803 = -0.99321 instead-0.97832), about 4 times smaller. Ifsinecosine values obtained werebe plotted, this algorithm would drawlogarithmic spiral rather thancircle.

A better, but still imperfect, recurrence formula

A simple recurrence formulagenerate trigonometric tablesbased on Euler's formula andrelation:

This leads tofollowing recurrencecompute trigonometric values sncn as above:

c0 = 1
s0 = 0
cn+1 = wr cn - wi sn
sn+1 = wi cn + wr sn
for n = 0,...,N-1, where wr = cos(2π/N)wi = sin(2π/N). These two starting trigonometric valuesusually computed using existing library functions (but could also be found e.g. by employing Newton's method incomplex planesolve forprimitive rootzN - 1).

This method would produce an exact tableexact arithmetic, but has errorsfinite-precision floating-point arithmetic. In fact,errors grow as O(ε N) (in bothworstaverage cases), where ε isfloating-point precision.

A significant improvement isusefollowing modification toabove,trick often usedgenerate trigonometric valuesFFT implementations:

c0 = 1
s0 = 0
cn+1 = cn - (αcn + β sn)
sn+1 = sn + (β cn - α sn)

where α = 2 sin2(π/N)β = sin(2π/N). The errorsthis methodmuch smaller, O(ε √N) on averageO(ε N) inworst case, but thisstill large enoughsubstantially degradeaccuracyFFTslarge sizes.


See also:

To come

References


Copyright 2004. All rights reserved.