Convert magnitude and/or a phase angle signal to complex signal
expand all in page
Libraries:
Simulink / Math Operations
HDL Coder / HDL Floating Point Operations
Description
Supported Operations
The Magnitude-Angle to Complex block converts magnitude and phase angleinputs to a complex output. The angle input must be in rad.
When there are two block inputs, the block supports these combinations of inputdimensions:
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 Usage | Effect of Out-of-Range Input |
---|---|
Simulation modes | An error appears. |
Generated code | Undefined behavior occurs. |
When you use the CORDIC approximation, ensure that you use an in-range input for theMagnitude-Angle to Complex block. Avoid relying on undefinedbehavior for generated code or accelerator modes.
Examples
expand all
Construct Complex Signal from Magnitude and Phase Angle
Open Model
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
|u| — Magnitude
scalar | vector | matrix
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 otherinput must use the same data type. For example, both signalsmust be
double
orsingle
.Fixed-point data types are supported only when you set theApproximation method to
CORDIC
. When one input has afixed-point data type, the other input must also have afixed-point data type.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fixed point
∠u — Radian phase angle
scalar | vector | matrix
Radian phase angle, specified as a real-valued scalar, vector, ormatrix. To compute the CORDIC approximation, the input angle must bebetween:
[–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 otherinput must use the same data type. For example, both signalsmust be
double
orsingle
.Fixed-point data types are supported only when you set theApproximation method to
CORDIC
. If one input has afixed-point data type, the other input must also have afixed-point data type.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fixed point
Port_1 — Magnitude or radian phase angle
scalar | vector | matrix
Magnitude, or radian phase angle, specified as a real-valued scalar,vector, or matrix.
When you set Input to
Magnitude
, you specify themagnitude at the input port, and the angle on the dialogbox.When you set Input to
Angle
, you specify the angle atthe input port, and the magnitude on the dialog box.
Dependencies
To enable this port, set Input toMagnitude
orAngle
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fixed point
Output
expand all
Port_1 — Complex signal
scalar | vector | matrix
Complex signal, formed from the magnitude and phase angle youspecify.
If the block input is an array, the output is an array of complexsignals. The elements of a magnitude input vector map to the magnitudesof the corresponding complex output elements. Similarly, the elements ofan angle input vector map to the angles of the corresponding complexoutput elements. If one input is a scalar, it maps to the correspondingcomponent (magnitude or angle) of all the complex output signals.
Data Types: single
| double
| fixed point
Parameters
expand all
Input — Type of input
Magnitude
(default) | Angle
| Magnitude and angle
Specify the kind of input: a magnitude input, an angle input, orboth.
Programmatic Use
Block Parameter:Input |
Type: character vector |
Values:'Magnitude' | 'Angle' | 'Magnitude andangle' |
Default:'Magnitude and angle' |
Angle — Phase angle of output
0
(default) | real-valued scalar, vector, or matrix
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 toMagnitude
.
Programmatic Use
Block Parameter:ConstantPart |
Type: character vector |
Values: constantscalar |
Default:'0' |
Magnitude — Magnitude of output
0
(default) | real-valued scalar, vector, or matrix
Constant magnitude of the output signal, specified as a real-valuedscalar, vector, or matrix.
Dependencies
To enable this parameter, set Input toAngle
.
Programmatic Use
Block Parameter:ConstantPart |
Type: character vector |
Values:real-valued scalar, vector, ormatrix |
Default:'0' |
Approximation method — CORDIC or none
None
(default) | CORDIC
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 seriesalgorithm. |
CORDIC | Floating point and fixed point | You want a fast, approximate calculation. |
When you use the CORDIC approximation, follow these guidelines for the inputangle:
For signed fixed-point types, the input angle must fall within therange [–2π, 2π) rad.
For unsigned fixed-point types, the input angle must fall withinthe range [0, 2π) rad.
The block uses the following data type propagation rules:
Data Type of Magnitude Input | Approximation Method | Data Type of Complex Output |
---|---|---|
Floating point |
| Same as input |
Signed, fixed point |
|
where |
Unsigned, fixed point |
|
where |
Programmatic Use
Block Parameter:ApproximationMethod |
Type: character vector |
Values:'None' | 'CORDIC' |
Default:'None' |
Number of iterations — Number of iterations for CORDIC algorithm
11
(default) | positive integer, less than or equal to word length of fixed-pointinput
Number of iterations to perform the CORDIC algorithm. The range ofpossible values depends on the data type of the input:
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 lengthof the magnitude input or the word length of the phase angleinput, whichever value is smaller |
Dependencies
To enable this parameter, set Approximationmethod to CORDIC
.
Programmatic Use
Block Parameter:NumberOfIterations |
Type: character vector |
Values: positive integer, lessthan or equal to word length of fixed-point input |
Default:'11' |
Scale output by reciprocal of gain factor — Scale real and imaginary parts of complex output
on
(default) | off
Select this check box to scale the real and imaginary parts of the complexoutput by a factor of (1/CORDIC gain)
. This value dependson the number of iterations you specify. As the number of iterations goesup, the value approaches 1.647.
This check box is selected by default, which leads to a more numericallyaccurate result for the complex output, X + iY
. However,scaling the output adds two extra multiplication operations, one forX
and one for Y
.
Dependencies
To enable this parameter, set Approximationmethod to CORDIC
.
Programmatic Use
Block Parameter:ScaleReciprocalGainFactor |
Type: character vector |
Values:'on' | 'off' |
Default:'on' |
Sample time (-1 for inherited) — Interval between samples
-1
(default) | scalar | vector
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
Block Parameter: SampleTime |
Type: string scalar or character vector |
Default: "-1" |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
expand all
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.
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™.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides additional configuration options that affect HDLimplementation and synthesized logic.
HDL Architecture
This block has multi-cycle implementations that introduce additionallatency in the generated code. To see the added latency, view thegenerated model or validation model. See Generated Model and Validation Model (HDL Coder).
HDL Block Properties
General
HDL Property | Description |
---|---|
ConstrainedOutputPipeline | Number of registers to place at the outputs bymoving existing delays within your design. Distributedpipelining does not redistribute these registers. Thedefault is |
InputPipeline | Number of input pipeline stages to insert in thegenerated code. Distributed pipelining and constrainedoutput pipelining can move these registers. The defaultis |
OutputPipeline | Number of output pipeline stages to insert in thegenerated code. Distributed pipelining and constrainedoutput pipelining can move these registers. The defaultis |
LatencyStrategy | Specify whether to map the blocks in your design to |
CustomLatency | When LatencyStrategy is set to |
Native Floating Point
HDL Property | Description |
---|---|
HandleDenormals | Specify whether you want HDL Coder to insert additional logic to handledenormal numbers in your design. Denormal numbers arenumbers that have magnitudes less than the smallestfloating-point number that can be represented withoutleading zeros in the mantissa. The default is |
InputRangeReduction | Specify whether your input range is bounded orunbounded. If your input range is unbounded, enable thisproperty for HDL Coder to insert additional logic to reduce therange of inputs to |
MantissaMultiplyStrategy | Specify how to implement the mantissamultiplication operation during code generation. Byusing different settings, you can control the DSP usageon the target FPGA device. The default is |
Fixed-Point Support
You can generate code for Magnitude Angle to complex block with fixed-pointdata types as input. To generate the code with fixed-point data types for theblock, set Input to Magnitude andangle
and the Approximation method toCORDIC
. When using the CORDIC approximationmethod, the block adds additional cycles of latency as given in tablebelow.
Architecture | Parameter | Additional cycles of latency |
---|---|---|
Pol2CartCordic | Number ofiterations Scaleoutput by reciprocal of gainfactor | When Scale output by reciprocal of gainfactor parameter is Max Latency =Number of iterations +1. When Scale output by reciprocalof gain factor parameter is Max Latency =Number of iterations +6. |
Restrictions
Fixed-point data types are not supported when you setInput to Magnitude
orAngle
.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
The Magnitude-Angle to Complex block supports fixed-point and base integer datatypes when you set Approximation method toCORDIC
.
Version History
Introduced before R2006a
expand all
R2024a: Generate HDL code with fixed-point data types
Starting in R2024a, you can generate HDL code for Magnitude-Angle to Complex blockthat uses fixed-point data types as inputs. To generate code with fixed-point datatypes, set the Input block parameter to Magnitudeand angle
and the Approximation methodparameter to CORDIC
. When using the CORDIC approximationmethod, you can also enable Scale output by reciprocal of gainfactor to scale the real and imaginary parts of the complex output bya gain factor.
See Also
Complex to Magnitude-Angle | Complex to Real-Imag | Real-Imag to Complex
Topics
- Complex Signals
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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:
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
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office