Shop OBEX P1 Docs P2 Docs Learn Events
How many points for Sine Table? — Parallax Forums

How many points for Sine Table?

IBIB Posts: 3
edited 2007-04-13 17:28 in Propeller 1
Hi everybody,
I've some doubts on the sine table.

The values of the sine for angles between 0° and 90° are divided into 2049 samples. Now, for each (unsigned) sample 12 bits should be enough, but 16 bits are used instead.
The questions are:
why 16 bits?
with 16 bits we can have 65536 values, but as we understand we are just using 2049 of them. How are the 2049 values choosen? What are the advantages? Are we completely missing the point?

The function "getsin" (or "getcos") reported on the page 423 of the manual takes as input an angle from 0° to 360°.
The question is: should I use a 14-bits values to express the angle? (4 x 2049 = 8196 => 14 bits)

If I want to generate a sine-wave signal using the audio amplifier of the demo-board, is it enough to change the freqb register of a timer set as follows within a certain sampling period?

movs     ctrb,#10 
movd     ctrb,#11
movi      ctrb,#%00111_000




Thanks,
IB.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-13 16:41
    The range 0 to 90 degrees is divided into 2048 equal intervals. The table includes both endpoints because it's is used in reverse for the cosine and the extra point makes this easier. Memory comes in units of 8 bits, so 16 bits is as easy to provide as 12 bits and gives us a little more accuracy.

    You actually need 13 bits to represent the angle from 0 to 359.9999.... degrees. There are only 2048 values per quadrant since the 2049th value is the same as the first value of the next quadrant, thus you have 4 x 2048 = 8192 which requires 13 bits.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-13 16:54
    Tracy Allen posted a sinewave generator some time ago that just needs a little filtering to produce fairly clean sine waves. I can't find the link, but here is a copy of it.
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-04-13 17:13
    The values in the table are computed for the table with 2^16 possible values for y:

    y = 65535 * sin(theta) for theta = 0 to 90 degrees, 2048 equal intervals with 2049 end points

    That gives better precision for y than would be had from 12 bits, y' = 4096 sin(theta). Yes you enter with 2^13 bits and use the top two bits for the quadrant, and 11 bits to index into the table.

    It is possible to enter with more bits and interpolate. For example, if you enter with 16 bits to describe a circle, then bits 14, 15 would be the quadrant, bit 3 to 13 would index into the table, and bits 0 to 2 could be used for interpolation.

    Here is the link to a tutorial that shows specifically how to generate a sine wave output using one counter for phase and one counter for amplitude.

    http://forums.parallax.com/showthread.php?p=606978

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • cgraceycgracey Posts: 14,133
    edited 2007-04-13 17:28
    The sine table gives 8,192 16-bit samples for a complete circle. It must be read in the following order for a complete circle:

    sample[noparse][[/noparse]0 to 2047]

    sample[noparse][[/noparse]2048 to 1]

    -sample[noparse][[/noparse]0 to 2047]

    -sample[noparse][[/noparse]2048 to 1]

    The funny overlaps are to ensure minimal and symmetrical·0 and 180 degree points and maximal and symmetrical 90 and 270 degree points.

    To output sine waves, an RC integrator must be driven with delta-modulated (CTR mode) sine samples. Attached is a program that generates sine wave outputs on pins 10 and 11 and sweeps their frequencies at different rates.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.

    Post Edited (Chip Gracey (Parallax)) : 4/13/2007 5:32:41 PM GMT
Sign In or Register to comment.