# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# Magnitude-Angle to Complex

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

Math Operations

## Description

### Supported 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.

### Effect of Out-of-Range Input on CORDIC Approximations

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 UsageEffect of Out-of-Range Input
SimulationAn error appears.
Generated codeUndefined 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.

## Definitions

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

## Data Type Support

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.

## Parameters

Input

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

Angle (Magnitude)
InputWhat 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 MethodData Types SupportedWhen 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 InputApproximation MethodData Type of Complex Output

Floating point

`None` or `CORDIC`

Same as input

Signed, fixed point

`CORDIC`

`fixdt`(1, `WL` + 2, `FL`)

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

Unsigned, fixed point

`CORDIC`

`fixdt`(1, `WL` + 3, `FL`)

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

Number of iterations

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

Data Type of Block InputsValue You Can Specify
Floating pointA positive integer
Fixed pointA 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.

## Characteristics

 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

Complex to Magnitude-Angle

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