Main Content

Magnitude-Angle to Complex

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

  • Magnitude-Angle to Complex block

Libraries:
Simulink / Math Operations
HDL Coder / HDL Floating Point 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 rad.

When there are two block inputs, the block supports these combinations of input dimensions:

  • 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 [1], the block input for phase angle has these restrictions:

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

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

This table summarizes the effects of an out-of-range input:

Block UsageEffect of Out-of-Range Input
Simulation modesAn error appears.
Generated codeUndefined behavior occurs.

When you use the CORDIC approximation, ensure that you use an in-range input for the Magnitude-Angle to Complex block. Avoid relying on undefined behavior for generated code or accelerator modes.

Examples

expand all

This example shows how to use the Magnitude-Angle to Complex block to construct a complex-valued signal. You can provide both the magnitude and phase angle as block inputs, or provide one value as an input, and the other on the block dialog box.

Ports

Input

expand all

Magnitude, specified as a real-valued scalar, vector, or matrix.

Dependencies

  • To enable this port, set Input to Magnitude and angle.

Limitations

  • If one input has a floating-point data type, the other input must use the same data type. For example, both signals must be double or single.

  • Fixed-point data types are supported only when you set the Approximation method to CORDIC. When one input has a fixed-point data type, the other input must also have a fixed-point data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Radian phase angle, specified as a real-valued scalar, vector, or matrix. To compute the CORDIC approximation, the input angle must be between:

  • [–2π, 2π) rad, for signed fixed-point types

  • [0, 2π) rad, for unsigned fixed-point types

For more information, see Effect of Out-of-Range Input on CORDIC Approximations.

Dependencies

  • To enable this port, set Input to Magnitude and angle.

Limitations

  • If one input has a floating-point data type, the other input must use the same data type. For example, both signals must be double or single.

  • Fixed-point data types are supported only when you set the Approximation method to CORDIC. If one input has a fixed-point data type, the other input must also have a fixed-point data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Magnitude, or radian phase angle, specified as a real-valued scalar, vector, or matrix.

  • When you set Input to Magnitude, you specify the magnitude at the input port, and the angle on the dialog box.

  • When you set Input to Angle, you specify the angle at the input port, and the magnitude on the dialog box.

Dependencies

To enable this port, set Input to Magnitude or Angle.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Complex signal, formed from the magnitude and phase angle you specify.

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.

Data Types: single | double | fixed point

Parameters

expand all

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

Programmatic Use

Block Parameter: Input
Type: character vector
Values: 'Magnitude' | 'Angle' | 'Magnitude and angle'
Default: 'Magnitude and angle'

Constant phase angle of the output signal, in rad. To compute the CORDIC approximation, the input angle must be between:

  • [–2π, 2π) rad, for signed fixed-point types

  • [0, 2π) rad, for unsigned fixed-point types

For more information, see Effect of Out-of-Range Input on CORDIC Approximations.

Dependencies

To enable this parameter, set Input to Magnitude.

Programmatic Use

Block Parameter: ConstantPart
Type: character vector
Values: constant scalar
Default: '0'

Constant magnitude of the output signal, specified as a real-valued scalar, vector, or matrix.

Dependencies

To enable this parameter, set Input to Angle.

Programmatic Use

Block Parameter: ConstantPart
Type: character vector
Values:real-valued scalar, vector, or matrix
Default: '0'

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 the input angle:

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

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

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

Programmatic Use

Block Parameter: ApproximationMethod
Type: character vector
Values: 'None' | 'CORDIC'
Default: 'None'

Number of iterations to perform the CORDIC algorithm. The range of possible values depends on the data type of the input:

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

Dependencies

To enable this parameter, set Approximation method to CORDIC.

Programmatic Use

Block Parameter: NumberOfIterations
Type: character vector
Values: positive integer, less than or equal to word length of fixed-point input
Default: '11'

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.

Dependencies

To enable this parameter, set Approximation method to CORDIC.

Programmatic Use

Block Parameter: ScaleReciprocalGainFactor
Type: character vector
Values: 'on' | 'off'
Default: 'on'

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. For more information, see Specify Sample Time.

Dependencies

This parameter is visible only if you set it to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: SampleTime
Values: "-1" (default) | scalar or vector in quotes

Block Characteristics

Data Types

double | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

More About

expand all

References

[1] Volder, Jack E., “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers EC-8 (1959); 330–334.

[2] Andraka, Ray “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): 191–200.

[3] Walther, J.S., “A Unified Algorithm for Elementary Functions,” Proceedings of the Spring Joint Computer Conference, May 18-20, 1971: 379–386.

[4] Schelin, Charles W., “Calculator Function Approximation,” The American Mathematical Monthly 90, no. 5 (1983): 317–325.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a

expand all