Main Content

cordiccart2pol

CORDIC-based transformation of Cartesian coordinates to polar

Description

[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.

example

[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

This example shows how to 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_flt = 
2.3562
rho_c2p_flt = 
0.7071
[theta_c2p_fxp,rho_c2p_fxp] = cordiccart2pol(fi(-0.5,1,16,15),fi(0.5,1,16,15))
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,rho_mlb_flt] = cart2pol(-0.5,0.5)
theta_mlb_flt = 
2.3562
rho_mlb_flt = 
0.7071

This example shows how to 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_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,rho] = cordiccart2pol(fi([0.75:-0.25:-1.0],1,16,15),fi(-0.5,1,16,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.

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 R2011b