Documentation Center

  • Trial Software
  • Product Updates

cordicpol2cart

CORDIC-based approximation of polar-to-Cartesian conversion

Syntax

[x,y] = cordicpol2cart(theta,r)
[x,y] = cordicpol2cart(theta,r,niters)
[x,y] = cordicpol2cart(theta,r,Name,Value)
[x,y] = cordicpol2cart(theta,r,niters,Name,Value)

Description

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

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

[x,y] = cordicpol2cart(theta,r,Name,Value) scales the output depending on the Boolean value of b.

[x,y] = cordicpol2cart(theta,r,niters,Name,Value) specifies both the number of iterations and Name,Value pair for whether to scale the output.

Input Arguments

theta

theta can be a signed or unsigned scalar, vector, matrix, or N-dimensional array containing the angle values in radians. All values of theta must be in the range [–2π 2π).

r

r contains the input magnitude values and can be a scalar or have the same dimensions as theta. r must be real valued.

niters

niters is the number of iterations the CORDIC algorithm performs. This argument is optional. When specified, niters must be a positive, integer-valued scalar. If you do not specify niters, or if you specify a value that is too large, the algorithm uses a maximum value. For fixed-point operation, the maximum number of iterations is the word length of r or one less than the word length of theta, whichever is smaller. For floating-point operation, the maximum value is 52 for double or 23 for single. Increasing the number of iterations can produce more accurate results but also increases the expense of the computation and adds latency.

Name-Value Pair Arguments

Optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes ('').

'ScaleOutput'

ScaleOutput is a Boolean value that specifies whether to scale the output by the inverse CORDIC gain factor. This argument is optional. If you set ScaleOutput to true or 1, the output values are multiplied by a constant, which incurs extra computations. If you set ScaleOutput to false or 0, the output is not scaled.

Default: true

Output Arguments

[x,y]

[x,y] contains the approximated Cartesian coordinates. When the input r is floating point, the output [x,y] has the same data type as the input.

When the input r is a signed integer or 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 fixed point, the outputs [x,y] are signed fi objects. These fi objects have word lengths are three bits larger than that of r. Their fraction lengths are the same as the fraction length of r.

Examples

Run the following code, and evaluate the accuracy of the CORDIC-based Polar-to-Cartesian conversion.

wrdLn = 16;
theta = fi(pi/3, 1, wrdLn);
u     = fi( 2.0, 1, wrdLn);

fprintf('\n\nNITERS\tX\t\t ERROR\t LSBs\t\tY\t\t ERROR\t LSBs\n');
fprintf('------\t-------\t ------\t ----\t\t-------\t ------\t ----\n');
for niters = 1:(wrdLn - 1)
 [x_ref, y_ref] = pol2cart(double(theta),double(u));
 [x_fi,  y_fi] = cordicpol2cart(theta, u, 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);
 fprintf('%d\t%1.4f\t %1.4f\t %1.1f\t\t%1.4f\t %1.4f\t %1.1f\n',...
   niters,x_dbl,x_err,(x_err * pow2(x_fi.FractionLength)),...
   y_dbl,y_err,(y_err * pow2(y_fi.FractionLength)));
end
fprintf('\n');

NITERS  X        ERROR    LSBs      Y      ERROR   LSBs
------	-------	 ------	 ----		-------	 ------	 ----
   1	   1.4142   0.4142   3392.8  1.4142   0.3178   2603.8
   2	   0.6324   0.3676   3011.2  1.8973   0.1653   1354.2
   3	   1.0737   0.0737   603.8   1.6873   0.0448   366.8
   4	   0.8561   0.1440   1179.2  1.8074   0.0753   617.2
   5	   0.9672   0.0329   269.2   1.7505   0.0185   151.2
   6	   1.0214   0.0213   174.8   1.7195   0.0126   102.8
   7	   0.9944   0.0056   46.2    1.7351   0.0031   25.2
   8	   1.0079   0.0079   64.8    1.7274   0.0046   37.8
   9	   1.0011   0.0011   8.8     1.7313   0.0007   5.8
   10   0.9978   0.0022   18.2    1.7333   0.0012   10.2
   11   0.9994   0.0006   5.2     1.7323   0.0003   2.2
   12   1.0002   0.0002   1.8     1.7318   0.0002   1.8
   13   0.9999   0.0002   1.2     1.7321   0.0000   0.2
   14   0.9996   0.0004   3.2     1.7321   0.0000   0.2
   15   0.9998   0.0003   2.2     1.7321   0.0000   0.2

More About

expand 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 also increases the expense of the computation and adds latency.

Algorithms

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.

References

[1] Volder, JE. "The CORDIC Trigonometric Computing Technique." IRE Transactions on Electronic Computers. Vol. EC-8, September 1959, pp. 330–334.

[2] Andraka, R. "A survey of CORDIC algorithm for FPGA based computers." Proceedings of the 1998 ACM/SIGDA sixth international symposium on Field programmable gate arrays. Feb. 22–24, 1998, pp. 191–200.

[3] Walther, J.S. "A Unified Algorithm for Elementary Functions." Hewlett-Packard Company, Palo Alto. Spring Joint Computer Conference, 1971, pp. 379–386. (from the collection of the Computer History Museum). www.computer.org/csdl/proceedings/afips/1971/5077/00/50770379.pdf

[4] Schelin, Charles W. "Calculator Function Approximation." The American Mathematical Monthly. Vol. 90, No. 5, May 1983, pp. 317–325.

See Also

| |

Was this topic helpful?