This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

dsp.HDLComplexToMagnitudeAngle System object

Magnitude and phase angle of complex signal—optimized for HDL code generation


The dsp.HDLComplexToMagnitudeAngle System object™ computes the magnitude and phase angle of a complex signal. It provides hardware-friendly control signals. The object uses a pipelined coordinate rotation digital computer (CORDIC) algorithm to achieve an efficient HDL implementation.

To compute the magnitude and phase angle of a complex signal:

  1. Create the dsp.HDLComplexToMagnitudeAngle object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).



HCMA = dsp.HDLComplexToMagnitudeAngle
HCMA = dsp.HDLComplexToMagnitudeAngle(Name,Value)


HCMA = dsp.HDLComplexToMagnitudeAngle returns a System object, HCMA, that computes the magnitude and phase angle of a complex input.


HCMA = dsp.HDLComplexToMagnitudeAngle(Name,Value) returns a System object, HCMA, sets properties using one or more name-value pairs. Enclose each property name in single quotes. For example,

cma = dsp.HDLComplexToMagnitudeAngle('AngleFormat','Radians')


expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Output values the object returns. The object returns the magnitude, or angle, or both.

Format of the angle output of the object, specified as either:

  • 'Normalized' — Fixed-point format that normalizes the angles in the range [–1,1].

  • 'Radians' — Fixed-point values between π and −π.

Scale output by the inverse of the CORDIC gain factor, specified as true or false.


If you turn off output scaling and apply the CORDIC gain elsewhere in your design, you must exclude the π/4 term. The quadrant mapping algorithm replaces the first CORDIC iteration by mapping inputs onto the angle range, [0,π/4]. Therefore, the initial rotation does not contribute a gain term.

Source of the NumIterations property for the CORDIC algorithm, specified as:

  • 'Property' — Uses the NumIterations property.

  • 'Auto' — Sets the number of iterations to input word length – 1. If the input is double or single, the number of iterations is 16.

Number of CORDIC iterations that the object executes, specified as an interger. The number of iterations must be less than or equal to the input word length – 1.


To enable this property, set NumIterationsSource to 'Property'.


For versions earlier than R2016b, use the step function to run the System object™ algorithm. The arguments to step are the object you created, followed by the arguments shown in this section.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.


[mag,angle,validOut] = HCMA(X,validIn)
[mag,validOut] = HCMA(X,validIn)
[angle,validOut] = HCMA(X,validIn)



[mag,angle,validOut] = HCMA(X,validIn) converts complex scalar X into its component magnitude and angle. validIn and validOut are logical scalars that indicate the validity of the input and output signals respectively. If validOut is 1 (true), the output is valid.

[mag,validOut] = HCMA(X,validIn) converts complex scalar X into its component magnitude.

To use this syntax, set OutputValue to 'Magnitude'. For example:

HCMA = dsp.HDLComplextoMagnitudeAngle('OutputValue','Magnitude');
[mag,validOut] = HCMA(X,validIn)

[angle,validOut] = HCMA(X,validIn) converts complex scalar X into its component angle.

To use this syntax, set OutputValue to 'Angle'. For example

HCMA = dsp.HDLComplextoMagnitudeAngle('OutputValue','Angle');
[angle,validOut] = HCMA(X,validIn)

Input Arguments

expand all

Input data, specified as a complex scalar value. double and single are allowed for simulation but not for HDL code generation.

Data Types: fi | int8 | int16 | int32 | uint8 | uint16 | uint32 | single | double
Complex Number Support: Yes

Validity of the X value, specified as a logical scalar.

Data Types: logical

Output Arguments

expand all

Magnitude calculated from complex input, returned as a scalar value with the same data type as the input data.

Angle calculated from complex input, returned as a scalar value with the same data type as the input data. The format of this value depends on the AngleFormat property.

Validity of the output data, returned as a logical scalar.

Data Types: logical

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

stepRun System object algorithm
cloneCreate duplicate System object
getNumInputsNumber of inputs required to call the System object
getNumOutputsNumber of outputs from calling the System object
isLockedDetermine if System object is locked
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object


expand all

Use the dsp.HDLComplextoMagnitudeAngle object to compute the magnitude and angle of a complex signal. The object uses a CORDIC algorithm for an efficient hardware implementation.

Choose word lengths and create random complex input data. Than, convert the input to fixed-point.

a = -4;
b = 4;
inputWL = 16;
inputFL = 12;
numSamples = 10;
reData = ((b-a).*rand(numSamples,1)+a);
imData = ((b-a).*rand(numSamples,1)+a);
dataIn = (fi(reData+imData*1i,1,inputWL,inputFL));
title('Random Complex Input Data')

Write a function that creates and calls the System object™. You can generate HDL from this function.

Note: This object syntax runs only in R2016b or later. If you are using an earlier release, replace each call of an object with the equivalent step syntax. For example, replace myObject(x) with step(myObject,x).

function [mag,angle,validOut] = Complex2MagAngle(yIn,validIn)
% Converts one sample of complex data to magnitude and angle data.
% yIn is a fixed-point complex number.
% validIn is a logical scalar value.
% You can generate HDL code from this function.

  persistent cma;
  if isempty(cma)
    cma = dsp.HDLComplexToMagnitudeAngle('AngleFormat','Radians');
  [mag,angle,validOut] = cma(yIn,validIn);

The object takes some latency to computer the answer for each input sample, depending on the number of CORDIC iterations. When you set NumIterationsSource to 'Auto', the number of iterations is inputWL-1. The latency is NumIterations+2, or inputWL+1.

latency = inputWL+1;
mag = zeros(1,numSamples+latency);
ang = zeros(1,numSamples+latency);
validOut = false(1,numSamples+latency);

Call the function to convert each sample. After you apply all input samples, continue calling the function with invalid input to flush remaining output samples.

for ii = 1:1:numSamples
   [mag(ii),ang(ii),validOut] = Complex2MagAngle(dataIn(ii),true);
for ii = (numSamples+1):1:(numSamples+latency)
   [mag(ii),ang(ii),validOut(ii)] = Complex2MagAngle(fi(0+0*1i,1,inputWL,inputFL),false);
% Remove non-valid output values
mag = mag(validOut == 1);
ang = ang(validOut == 1);
polar(ang,mag,'--r')   % Red is output from HDL-optimized object
title('Output from dsp.HDLComplexToMagnitudeAngle')
magD = abs(dataIn);
angD = angle(dataIn);
polar(angD,magD,'--g') % Green is output from abs and angle functions
title('Output from abs and angle Functions')


expand all

This object implements the algorithm described on the Complex to Magnitude-Angle HDL Optimized block reference page.

Introduced in R2014b

Was this topic helpful?