Main Content

cordicpol2cart

CORDIC-based approximation of polar-to-Cartesian conversion

Description

[x,y] = cordicpol2cart(theta,r) returns the Cartesian x- and y-coordinates of r*e^(j*theta) using a CORDIC algorithm approximation.

[x,y] = cordicpol2cart(theta,r,niters) performs niters iterations of the algorithm.

example

[x,y] = cordicpol2cart(___,'ScaleOutput',b) scales the output depending on the Boolean value of b.

Examples

collapse all

Run this code to evaluate the accuracy of the CORDIC-based polar-to-Cartesian conversion for a given number of iterations of the algorithm.

wl = 16;
theta = fi(pi/3,1,wl);
r = fi(2,1,wl);

results_array = [];
for niters = 1:(wl-1)
    [x_ref,y_ref] = pol2cart(double(theta),double(r));
    [x_fi,y_fi] = cordicpol2cart(theta,r,niters);

    x_dbl = double(x_fi);
    y_dbl = double(y_fi);

    x_err = abs(x_dbl - x_ref);
    y_err = abs(y_dbl - y_ref);

    x_LSBs = x_err*pow2(x_fi.FractionLength);
    y_LSBs = y_err*pow2(y_fi.FractionLength);

    result = [niters,x_dbl,x_err,x_LSBs,...
             y_dbl,y_err,y_LSBs];
    results_array = [results_array; result];
end

results_table = array2table(results_array,'VariableNames',...
    {'NITERS','X','X ERROR','X LSBs','Y','Y ERROR','Y LSBs'})
results_table=15×7 table
    NITERS       X        X ERROR      X LSBs      Y        Y ERROR      Y LSBs 
    ______    _______    __________    ______    ______    __________    _______

       1       1.4142       0.41415    3392.8    1.4142       0.31785     2603.8
       2      0.63245       0.36758    3011.2    1.8973       0.16531     1354.2
       3       1.0737        0.0737    603.75    1.6873      0.044778     366.82
       4      0.85608       0.14395    1179.2    1.8074       0.07534     617.18
       5      0.96716      0.032867    269.25    1.7505      0.018455     151.18
       6       1.0214      0.021332    174.75    1.7195      0.012551     102.82
       7      0.99438     0.0056453    46.247    1.7351      0.003074     25.182
       8       1.0079     0.0079045    64.753    1.7274     0.0046164     37.818
       9       1.0011     0.0010685    8.7535    1.7313    0.00071019     5.8179
      10       0.9978     0.0022274    18.247    1.7333     0.0012429     10.182
      11      0.99939    0.00064045    5.2465    1.7323    0.00026637     2.1821
      12       1.0002    0.00021405    1.7535    1.7318    0.00022191     1.8179
      13      0.99988    0.00015217    1.2465    1.7321    2.2232e-05    0.18213
      14      0.99963    0.00039631    3.2465    1.7321    2.2232e-05    0.18213
      15      0.99976    0.00027424    2.2465    1.7321    2.2232e-05    0.18213

Input Arguments

collapse all

Angular coordinate, specified as a real-valued signed or unsigned scalar, vector, matrix, or multidimensional array containing the angle values in radians. All values of theta must be in the range [-2π 2π).

theta and r must be of the same data type class. That is, if theta is a double then r must be a double, if theta is an integer type, then r must be an integer type, if theta is a fixed-point type, then r must be a fixed-point type, and so on.

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

Input magnitude values, specified as a real-valued scalar, vector, matrix, or multidimensional array. If r is not a scalar, it must have the same dimensions as theta.

theta and r must be of the same data type class. That is, if theta is a double then r must be a double, if theta is an integer type, then r must be an integer type, if theta is a fixed-point type, then r must be a fixed-point type, and so on.

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 the word length of r or one less than the word length of theta, whichever is smaller.

  • 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

Whether to scale the output by the inverse CORDIC gain factor, specified as one of these values:

  • 1 — Multiply output values by a constant. This incurs extra computations.

  • 0 — Do not scale the output.

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

Output Arguments

collapse all

Approximated Cartesian coordinates, returned as scalars, vectors, matrices, or multidimensional arrays. The data type of the output depends on the input:

  • When the input r is floating point, the outputs [x,y] have the same data type as the input.

  • When the input r is a signed integer or a fixed-point data type, the outputs [x,y] are signed fi objects. These fi objects have word lengths that are two bits larger than that of r. Their fraction lengths are the same as the fraction length of r.

  • When the input r is an unsigned integer or a fixed-point data type, the outputs [x,y] are signed fi objects. These fi objects have word lengths that are three bits larger than that of r. Their fraction lengths are the same as the fraction length of r.

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. This algorithm takes its initial values for X, Y, and Z from the inputs, r and theta.

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 R2011a