[hpsdr] A sin & cos sample calculation algorithm

David McQuate mcquate at sonic.net
Tue Jan 19 17:47:42 PST 2010


An iterative algorithm that calculates sin & cos samples,
requiring only two adds, and two multiplies per sample,
is as follows.
Use four variables, A, B, C, and D.
Initialize A, B, and C to 1 (or whatever peak value you want)
Given a number of samples per cycle, N, calculate two multipliers,
M1 = - (2 pi / N)^2
M2 = N / (2 pi)

(note M1 is always negative, generally between zero and -1/2)
For each sample, calculate new values:
A' = M1 * C
B' = B + A'
C' = C + B'
D = M2 * C'

B' is the cos wave
D is the sin wave

B integrates the calculated A' values.
C integtrates the calculated B' values.
It seems to be numerically solving the second-order differential equation
d2/dx2( f(x) ) = -f(x)
which has solutions like sin(x) and cos(x).  This explains the value of M1.

I wonder how this algorithm compares to CORDIC ?
How would it do when used for digital down-conversion?
(For instance, if it were used in Mercury's FPGA...)

I've looked at it using Excel.  The calculated values are not perfect.  
The sum of the squares
of sin & cos varies from 0.9969 to 1.003
This seems to indicate that the calculations require a large number of bits.

(ref:  EDN magazine january 7, 2010, p50, a "design idea" by Daniele 
Danieli, of Venice, Italy)

73,
Dave



More information about the Hpsdr mailing list