Main Content

cordiccart2pol

Transform Cartesian coordinates to polar using CORDIC-based approximation

Description

example

[theta,rho] = cordiccart2pol(x,y) transforms corresponding elements of data stored in Cartesian coordinates x and y to polar coordinates theta and rho using a CORDIC algorithm approximation.

[theta,rho] = cordiccart2pol(x,y,niters) performs niters iterations of the CORDIC algorithm.

[theta,rho] = cordiccart2pol(___,'ScaleOutput',b) specifies whether to scale the output rho by the inverse CORDIC gain value.

Examples

collapse all

Convert fixed-point and floating-point Cartesian coordinates to polar coordinates using a CORDIC algorithm approximation. Compare the results to the MATLAB® cart2pol function.

[theta_c2p_flt,rho_c2p_flt] = cordiccart2pol(-0.5,0.5)
[theta_c2p_fxp,rho_c2p_fxp] = cordiccart2pol(fi(-0.5,1,16,15),fi(0.5,1,16,15))
[theta_mlb_flt,rho_mlb_flt] = cart2pol(-0.5,0.5)
theta_c2p_flt =

    2.3562


rho_c2p_flt =

    0.7071


theta_c2p_fxp = 

    2.3562

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 13

rho_c2p_fxp = 

    0.7071

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 18
        FractionLength: 15

theta_mlb_flt =

    2.3562


rho_mlb_flt =

    0.7071

Convert an array of fixed-point Cartesian coordinates to polar coordinates using a CORDIC algorithm approximation.

[theta_pos,rho] = cordiccart2pol(fi([0.75:-0.25:-1.0],1,16,15),fi(0.5,1,16,15))
[theta_neg,rho] = cordiccart2pol(fi([0.75:-0.25:-1.0],1,16,15),fi(-0.5,1,16,15))
theta_pos = 

    0.5881    0.7854    1.1072    1.5708    2.0344    2.3562    2.5535    2.6780

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 13

rho = 

    0.9014    0.7071    0.5591    0.5000    0.5591    0.7071    0.9014    1.1180

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 18
        FractionLength: 15

theta_neg = 

   -0.5881   -0.7854   -1.1072   -1.5708   -2.0344   -2.3562   -2.5535   -2.6780

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 13

rho = 

    0.9014    0.7071    0.5591    0.5000    0.5591    0.7071    0.9014    1.1180

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 18
        FractionLength: 15

Input Arguments

collapse all

Cartesian coordinates, specified as scalars, vectors, matrices, or multidimensional arrays. x and y must be the same size. If they are not the same size, at least one value must be a scalar. Both x and y must have the same data type.

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

Number of iterations the CORDIC algorithm performs, specified as a positive integer-valued scalar. 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 rho 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 rho by the inverse CORDIC gain value, 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

Angular coordinate, returned as an array. theta is the counterclockwise angle in the x-y plane measured in radians from the positive x-axis. The value of the angle is in the range [-pi pi].

If x and y are floating-point, then theta has the same data type as x and y. Otherwise, theta has a fixed-point data type with the same word length as x and y with a best-precision fraction length for the [-pi pi] range.

Radial coordinate, returned as an array. rho is the distance from the origin to a point in the x-y plane.

rho returns the polar coordinates radius magnitude values. rho is real-valued and can be a scalar or have the same dimensions as theta.

If the inputs x,y are fixed-point values, then rho is a signed fixed-point value with binary-point scaling. If the inputs x,y are signed, then the word length of rho is the input word length +2. If the inputs are unsigned, then the word length of rho is the input word length +3. The fraction length of rho is always the same as the fraction length of the x,y inputs.

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.

Algorithms

collapse all

Signal Flow Diagrams

CORDIC Vectoring Kernel

The accuracy of the CORDIC kernel depends on the choice of initial values for X, Y, and Z. This algorithm uses the following initial values:

x0 is initialized to the x input valuey0 is initialized to the y input valuez0 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 R2011b