Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Convert magnitude and/or a phase angle signal to complex signal

Math Operations

The Magnitude-Angle to Complex block converts magnitude and phase angle inputs to a complex output. The angle input must be in radians.

The block supports the following combinations of input dimensions when there are two block inputs:

Two inputs of equal dimensions

One scalar input and the other an n-dimensional array

If the block input is an array, the output is an array of complex signals. The elements of a magnitude input vector map to the magnitudes of the corresponding complex output elements. Similarly, the elements of an angle input vector map to the angles of the corresponding complex output elements. If one input is a scalar, it maps to the corresponding component (magnitude or angle) of all the complex output signals.

If you use the CORDIC approximation method (see Definitions), the block input for phase angle has the following restrictions:

For signed fixed-point types, the input angle must fall within the range [–2π, 2π) radians.

For unsigned fixed-point types, the input angle must fall within the range [0, 2π) radians.

The following table summarizes what happens for an out-of-range input:

Block Usage | Effect of Out-of-Range Input |
---|---|

Simulation | An error appears. |

Generated code | Undefined behavior occurs. |

Accelerator modes |

Ensure that you use an in-range input for the Magnitude-Angle to Complex block when you use the CORDIC approximation. Avoid relying on undefined behavior for generated code or Accelerator modes.

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.

The block accepts real input signals of the following data types:

Floating point

Fixed point (only when

**Approximation method**is`CORDIC`

)

The following restrictions also apply:

If one input uses a floating-point type, the other input must use the same data type. For example, both signals must be

`double`

or`single`

.If one input uses a fixed-point type, the other input must also use a fixed-point type.

**Input**Specify the kind of input: a magnitude input, an angle input, or both.

**Angle (Magnitude)**Input What to Specify `Magnitude`

The constant phase angle of the output signal in radians `Angle`

The constant magnitude of the output signal This parameter is not available when

**Input**is`Magnitude and angle`

.**Approximation method**Specify the type of approximation for computing output.

Approximation Method Data Types Supported When to Use This Method `None`

(default)Floating point

You want to use the default Taylor series algorithm.

`CORDIC`

Floating point and fixed point

You want a fast, approximate calculation.

When you use the CORDIC approximation, follow these guidelines:

For signed fixed-point types, the input angle must fall within the range [–2π, 2π) radians.

For unsigned fixed-point types, the input angle must fall within the range [0, 2π) radians.

The block uses the following data type propagation rules:

Data Type of Magnitude Input Approximation Method Data Type of Complex Output Floating point

`None`

or`CORDIC`

Same as input

Signed, fixed point

`CORDIC`

`fixdt`

(1,+ 2,`WL`

)`FL`

where

and`WL`

are the word length and fraction length of the magnitude`FL`

Unsigned, fixed point

`CORDIC`

`fixdt`

(1,+ 3,`WL`

)`FL`

where

and`WL`

are the word length and fraction length of the magnitude`FL`

**Number of iterations**Specify the number of iterations to perform the CORDIC algorithm. The default value is 11.

Data Type of Block Inputs Value You Can Specify Floating point A positive integer Fixed point A positive integer that does not exceed the word length of the magnitude input or the word length of the phase angle input, whichever value is smaller Entering a value that is not a positive integer causes an error.

This parameter is available when you set

**Approximation method**to`CORDIC`

.**Scale output by reciprocal of gain factor**Select this check box to scale the real and imaginary parts of the complex output by a factor of

`(1/CORDIC gain)`

. This value depends on the number of iterations you specify. As the number of iterations goes up, the value approaches 1.647.This check box is selected by default, which leads to a more numerically accurate result for the complex output,

`X + iY`

. However, scaling the output adds two extra multiplication operations, one for`X`

and one for`Y`

.This parameter is available when you set

**Approximation method**to`CORDIC`

.**Sample time****Note:**This parameter is not visible in the block dialog box unless it is explicitly set to a value other than`-1`

. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Data Types | Double | Single | Fixed-Point |

Sample Time | Inherited from driving block |

Direct Feedthrough | Yes |

Multidimensional Signals | Yes |

Variable-Size Signals | Yes |

Zero-Crossing Detection | No |

Code Generation | Yes |

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

Was this topic helpful?