How many points for Sine Table?
IB
Posts: 3
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?
Thanks,
IB.
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
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.
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
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