cordicpol2cart
CORDIC-based approximation of polar-to-Cartesian conversion
Syntax
Description
Examples
Evaluate Accuracy of CORDIC-Based Polar-to-Cartesian Conversion
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
theta
— Angular coordinate
scalar | vector | matrix | multidimensional array
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
r
— Input magnitude values
scalar | vector | matrix | multidimensional array
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
niters
— Number of iterations CORDIC algorithm performs
positive scalar integer
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:
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
b
— Whether to scale output by inverse CORDIC gain factor
1
(default) | 0
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
[x,y]
— Approximated Cartesian coordinates
scalars | vectors | matrices | multidimensional arrays
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 signedfi
objects. Thesefi
objects have word lengths that are two bits larger than that ofr
. Their fraction lengths are the same as the fraction length ofr
.When the input
r
is an unsigned integer or a fixed-point data type, the outputs[x,y]
are signedfi
objects. Thesefi
objects have word lengths that are three bits larger than that ofr
. Their fraction lengths are the same as the fraction length ofr
.
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.
More About
Algorithms
Signal Flow Diagrams
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:
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 cordicpol2cart
function also supports MATLAB® to High-Level Synthesis (HLS) code generation.
Version History
Introduced in R2011a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)