cordiccart2pol
Transform Cartesian coordinates to polar using CORDIC-based approximation
Syntax
Description
Examples
Convert Cartesian Coordinates to Polar
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 Array of Cartesian Coordinates to Polar
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
x,y
— Cartesian coordinates
scalars | vectors | matrices | multidimensional arrays
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
niters
— Number of iterations of CORDIC algorithm
positive integer-valued scalar
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:
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
b
— Whether to scale output rho
by inverse CORDIC gain value
1
(default) | 0
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
theta
— Angular coordinate
array
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.
rho
— Radial coordinate
array
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
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
Signal Flow Diagrams
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:
fimath Propagation Rules
CORDIC functions discard any local fimath
attached to the
input.
The CORDIC functions use their own internal fimath
when performing calculations:
OverflowAction
—Wrap
RoundingMethod
—Floor
The output has no attached fimath
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Variable-size signals are not supported.
The number of iterations the CORDIC algorithm performs,
niters
, must be a constant.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
The cordiccart2pol
function also supports MATLAB to High-Level Synthesis (HLS) code generation.
Version History
Introduced in R2011b
See Also
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)