Main Content

cordiccexp

CORDIC-based approximation of complex exponential

Description

y = cordiccexp(theta) computes cos(theta) + j*sin(theta) using a CORDIC algorithm approximation and returns the approximated complex result in y.

y = cordiccexp(theta,niters) performs niters iterations of the algorithm.

example

Examples

collapse all

See the effect of the number of iterations on the result of the cordiccexp approximation.

wl = 8;
theta = fi(pi/2,1,wl);

output_type = fi([], 1,wl,wl - 2);
results_array = zeros(wl - 1,1,'like',output_type)';

for niters = 1:(wl - 1)
  cis    = cordiccexp(theta,niters);
  fl     = cis.FractionLength;
  x      = real(cis);
  y      = imag(cis);

  x_dbl  = double(x);
  y_dbl  = double(y);

  x_err  = abs(x_dbl - cos(double(theta)));
  y_err  = abs(y_dbl - sin(double(theta)));

  result = [niters,y_dbl,y_err,(y_err*pow2(fl)),...
      x_dbl,x_err,(x_err*pow2(fl))];
  results_array = [results_array; result];
end

results_table = array2table(results_array,'VariableNames',{'NITERS',...
    'Y (SIN)','Y ERROR','Y LSBs','X (COS)','X ERROR','X LSBs'})
results_table=8×7 table
    NITERS    Y (SIN)    Y ERROR     Y LSBs    X (COS)     X ERROR     X LSBs 
    ______    _______    ________    ______    ________    ________    _______

         0          0           0         0           0           0          0
         1    0.70312     0.29688    1.9844    -0.70312     0.70312     1.9844
    1.9844     0.9375      0.0625    1.9844     -0.3125      0.3125     1.9844
    1.9844    0.96875     0.03125    1.9844     -0.0625      0.0625     1.9844
    1.9844    0.96875     0.03125    1.9844      0.0625      0.0625     1.9844
    1.9844    0.98438    0.015625         1           0           0    0.46875
    1.9844    0.98438    0.015625         1     0.03125     0.03125     1.9844
    1.9844          1           0         0    0.015625    0.015625     1.4688

Input Arguments

collapse all

Input array, specified as a signed or unsigned scalar, vector, matrix, or multidimensional array. All values of theta must be real and in the range [-2π 2π).

If the input is a fi object, it must use binary-point scaling.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Number of iterations the CORDIC algorithm performs, specified as a positive scalar integer. Increasing the number of iterations can produce more accurate results but also increases the expense of the computation and adds latency.

If you do not specify niters, or if you specify a value that is too large, the algorithm uses a maximum value based on the data type of the inputs:

  • Fixed-point inputs — The maximum number of iterations is one less than the word length of theta.

  • Floating-point inputs — The maximum value is 52 for double or 23 for single.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Output Arguments

collapse all

Approximated complex exponential e^(j*theta), returned as a scalar, vector, matrix, or multidimensional array. The data type of the output depends on the input:

  • When the input theta is floating point, the output data type is the same as the input type.

  • When the input theta is fixed point, the output has the same word length as the input and a fraction length equal to the word length minus 2.

More About

collapse all

CORDIC

CORDIC is an acronym for COordinate Rotation DIgital Computer. The Givens rotation-based CORDIC algorithm is one of the most hardware-efficient algorithms available because it requires only iterative shift-add operations (see References). The CORDIC algorithm eliminates the need for explicit multipliers. Using CORDIC, you can calculate various functions such as sine, cosine, arc sine, arc cosine, arc tangent, and vector magnitude. You can also use this algorithm for divide, square root, hyperbolic, and logarithmic functions.

Increasing the number of CORDIC iterations can produce more accurate results, but doing so increases the expense of the computation and adds latency.

More About

Algorithms

collapse all

Signal Flow Diagrams

CORDIC Rotation Kernel

X represents the real part, Y represents the imaginary part, and Z represents theta. The accuracy of the CORDIC rotation kernel depends on the choice of initial values for X, Y, and Z. This algorithm uses these initial values:

  • z0 is initialized to the θ input argument value.

  • x0 is initialized to 1/AN.

  • y0 is initialized to 0.

fimath Propagation Rules

CORDIC functions discard any local fimath attached to the input.

The CORDIC functions use their own internal fimath when performing calculations:

  • OverflowActionWrap

  • RoundingMethodFloor

The output has no attached fimath.

Extended Capabilities

Version History

Introduced in R2010a