Expand description
Fixed-point CORDIC sine/cosine, in 32-bit and 64-bit word sizes.
The COordinate Rotation DIgital Computer computes sine and cosine with only shifts and adds: a
vector is rotated toward the target angle by a fixed sequence of micro-rotations of angle
atan(2^-i), each chosen clockwise or counter-clockwise. This implementation is entirely
integer arithmetic, as it would be in hardware, and the single algorithm is instantiated for two
word sizes:
| type | angle | results | max iterations | accuracy |
|---|---|---|---|---|
Cordic32 (alias Cordic) | u32 binary angle | i32, Q1.30 | 30 | about 1e-8 |
Cordic64 | u64 binary angle | i64, Q1.62 | 62 | about 4e-16 at 52 iterations |
A binary angle has 2^N units per turn, so it wraps naturally and its top two bits select the
quadrant. Results are signed (sine and cosine go negative) with 1.0 represented as
1 << FRACTIONAL_BITS. The micro-rotation angles and the cumulative gain compensation are
precomputed integer tables, and the shifts use round-to-nearest to keep the bias down.
Widening only the data would not help: the angle’s resolution limits the accuracy, so both words
grow together. Cordic32 is the hardware-style choice (1e-8 is about -160 dB, beyond what a
24-bit converter chain can use); Cordic64 matches the 64-bit phase of the NCO and reaches
double-precision accuracy, at the cost of about 1.7 times as many iterations.
See the book entry Signal sources: oscillators, CORDIC and waveforms.
Structs§
- Cordic32
- A 32-bit CORDIC rotator:
u32binary angles (2^32per turn) andi32Q1.30 results. Accurate to about 1e-8 (a dozen least-significant bits) at 30 iterations. - Cordic64
- A 64-bit CORDIC rotator:
u64binary angles (2^64per turn, the same width as the NCO phase) andi64Q1.62 results. Reaches double-precision accuracy (about 4e-16) at 52 iterations and about 3e-18 at the maximum of 62.
Constants§
- FRACTIONAL_
BITS - Number of fractional bits in
Cordic32results. - MAX_
ITERATIONS - The maximum number of
Cordic32micro-rotations. - ONE
- The
Cordic32fixed-point representation of 1.0.
Functions§
- angle_
from_ radians - Converts an angle in radians to a
u32binary angle (modulo one turn). - angle_
from_ turns - Converts an angle in turns to a
u32binary angle (modulo one turn). - angle_
to_ radians - Converts a
u32binary angle to radians in[0, 2*pi). - cordic_
sin_ cos - Returns
(sin(angle), cos(angle))for an angle in radians, using the 32-bit integer CORDIC withCordic32::DEFAULT_ITERATIONS(accurate to about 1e-8). UseCordic64for full double-precision accuracy.
Type Aliases§
- Cordic
- The 32-bit rotator, kept under its original name.