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.

Algorithms

collapse all

References

[1] Volder, Jack E. “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers. EC-8, no. 3 (Sept. 1959): 330–334.

[2] Andraka, Ray. “A Survey of CORDIC Algorithm for FPGA Based Computers.” In Proceedings of the 1998 ACM/SIGDA Sixth International Symposium on Field Programmable Gate Arrays, 191–200. https://dl.acm.org/doi/10.1145/275107.275139.

[3] Walther, J.S. “A Unified Algorithm for Elementary Functions.” In Proceedings of the May 18-20, 1971 Spring Joint Computer Conference, 379–386. https://dl.acm.org/doi/10.1145/1478786.1478840.

[4] Schelin, Charles W. “Calculator Function Approximation.” The American Mathematical Monthly, no. 5 (May 1983): 317–325. https://doi.org/10.2307/2975781.

Extended Capabilities

expand all

Version History

Introduced in R2010a