Magnitude and phase angle of complex signal (2024)

Table of Contents
Description Creation Syntax Description Properties OutputFormat — Type of values to return 'Magnitude and angle' (default) | 'Magnitude' | 'Angle' AngleFormat — Format of phase angle output value 'Normalized' (default) | 'Radians' ScaleOutput — Scale output by inverse of CORDIC gain factor true (default) | false NumIterationsSource — Source of NumIterations 'Auto' (default) | 'Property' NumIterations — Number of CORDIC iterations integer less than or equal to one less than the input word length ScalingMethod — Implementation of CORDIC gain scaling 'CSD' (default) | 'Multipliers' Usage Syntax Description Input Arguments X — Input signalcomplex scalar or vector validIn — Indicates valid input data scalar Output Arguments mag — Magnitude component of input signalscalar | vector angle — Phase angle component of input signal scalar | vector validOut — Indicates valid output data scalar Object Functions Common to All System Objects Examples Compute Magnitude and Phase Angle of Complex Signal Algorithms CORDIC Algorithm Modified CORDIC Algorithm Architecture Normalized Angle Format Delay Performance Extended Capabilities C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™. HDL Code GenerationGenerate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™. Version History R2022a: Moved to DSP HDL Toolbox from DSP System Toolbox R2022a: Option to use multiplier for scale factor R2021b: High-throughput interface See Also Blocks Functions MATLAB Command Americas Europe Asia Pacific FAQs

Magnitude and phase angle of complex signal

expand all in page

Description

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

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

  1. Create the dsphdl.ComplexToMagnitudeAngle 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?

Creation

Syntax

magAngle = dsphdl.ComplexToMagnitudeAngle

magAngle = dsphdl.ComplexToMagnitudeAngle(Name=Value)

Description

magAngle = dsphdl.ComplexToMagnitudeAngle returns a dsphdl.ComplexToMagnitudeAngle System object, magAngle, that computes the magnitude and phase angle of a complex input signal.

example

magAngle = dsphdl.ComplexToMagnitudeAngle(Name=Value) sets properties of the magAngle object using one or more name-value arguments.

Example: magAngle = dsphdl.ComplexToMagnitudeAngle(AngleFormat='Radians')

Properties

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.

Type of output values to return, specified as 'Magnitude and angle', 'Magnitude', or 'Angle'. You can choose for the object to return the magnitude of the input signal, or the phase angle of the input signal, or both.

Format of the phase angle output value from the object, specified as:

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

  • 'Radians' — Fixed-point values in the range [π,−π].

Scale output by the inverse of the CORDIC gain factor, specified as true or false. The object implements this gain factor with either CSD logic or a multiplier, according to the ScalingMethod property.

Note

If your design includes a gain factor later in the datapath, you can set ScaleOutput to false, and include the CORDIC gain factor in the later gain. For calculation of this gain factor, see Algorithm. The object replaces the first CORDIC iteration by mapping the input value 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:

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

  • 'Property' — Uses the NumIterations property.

For details of the CORDIC algorithm, see Algorithm.

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

For details of the CORDIC algorithm, see Algorithm.

Dependencies

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

When you set this property to 'CSD', the object implements the CORDIC gain scaling by using a shift-and-add architecture for the multiply operation. This implementation uses no multiplier resources and may increase the length of the critical path in your design. When you set this property to 'Multipliers', the object implements the CORDIC gain scaling with a multiplier and increases the latency of the object by four cycles.

Dependencies

To enable this property, set the ScaleOutput property to true.

Usage

Syntax

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

[mag,validOut]= magAngle(X,validIn)

[angle,validOut]= magAngle(X,validIn)

Description

example

[mag,angle,validOut]= magAngle(X,validIn) converts a scalar or vector of complex values X into their component magnitude and phase angles. validIn and validOut are logical scalars that indicate the validity of the input and output signals, respectively.

[mag,validOut]= magAngle(X,validIn) returns only the component magnitudes of X.

To use this syntax, set OutputFormat to 'Magnitude'.

Example: magAngle = dsphdl.ComplextoMagnitudeAngle(OutputFormat='Magnitude');

[angle,validOut]= magAngle(X,validIn) returns only the component phase angles of X.

To use this syntax, set OutputFormat to 'Angle'.

Example: magAngle = dsphdl.ComplextoMagnitudeAngle(OutputFormat='Angle');

Input Arguments

expand all

Input signal, specified as a scalar, a column vector representing samples in time, or a row vector representing channels. Using vector input increases data throughput while using more hardware resources. The object implements the conversion logic in parallel for each element of the vector. The input vector can contain up to 64 elements.

The software supports double and single data types for simulation, but not for HDL code generation.

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

Control signal that indicates if the input data is valid. When validIn is 1 (true), the object captures the values from the dataIn argument. When validIn is 0 (false), the object ignores the values from the dataIn argument.

Data Types: logical

Output Arguments

expand all

Magnitude calculated from the complex input signal, returned as a scalar, a column vector representing samples in time, or a row vector representing channels. The dimensions and data type of this argument match the dimensions of the dataIn argument.

Dependencies

To enable this argument, set the OutputFormat property to 'Magnitude and Angle' or 'Magnitude'.

Angle calculated from the complex input signal, returned as a scalar, a column vector representing samples in time, or a row vector representing channels. The dimensions and data type of this argument match the dimensions of the dataIn argument. The format of this value depends on the AngleFormat property.

Dependencies

To enable this argument, set the OutputFormat property to 'Magnitude and Angle' or 'Angle'.

Control signal that indicates if the output data is valid. When validOut is 1 (true), the object returns valid data from the mag and/or angle arguments. When validOut is 0 (false), values from the mag and/or angle arguments are not valid.

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:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Compute Magnitude and Phase Angle of Complex Signal

Open Script

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

Choose word lengths and create random complex input signal. Then, convert the input signal 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));figureplot(dataIn)title('Random Complex Input Data')xlabel('Real')ylabel('Imaginary')

Magnitude and phase angle of complex signal (1)

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

function [mag,angle,validOut] = Complex2MagAngle(yIn,validIn)%Complex2MagAngle % 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 = dsphdl.ComplexToMagnitudeAngle(AngleFormat='Radians'); end [mag,angle,validOut] = cma(yIn,validIn);end% Copyright 2021-2023 The MathWorks, Inc.

The number of CORDIC iterations determines the latency that the object takes to compute the answer for each input sample. The latency is NumIterations+4. In this example, NumIterationsSource is set to the default, 'Auto', so the object uses inputWL-1 iterations. The latency is inputWL+3.

latency = inputWL+3;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);endfor ii = (numSamples+1):1:(numSamples+latency) [mag(ii),ang(ii),validOut(ii)] = Complex2MagAngle(fi(0+0*1i,1,inputWL,inputFL),false);end% Remove invalid output valuesmag = mag(validOut == 1);ang = ang(validOut == 1);figurepolar(ang,mag,'--r') % Red is output from System objecttitle('Output from dsphdl.ComplexToMagnitudeAngle')magD = abs(dataIn);angD = angle(dataIn);figurepolar(angD,magD,'--b') % Blue is output from abs and angle functionstitle('Output from abs and angle Functions')

Magnitude and phase angle of complex signal (2)

Magnitude and phase angle of complex signal (3)

Algorithms

expand all

Extended Capabilities

This System object supports C/C++ code generation for accelerating MATLAB® simulations, and for DPI component generation.

Version History

Introduced in R2014b

expand all

Before R2022a, this System object was named dsp.HDLComplexToMagnitudeAngle and was part of the DSP System Toolbox™ product.

In previous releases, the System object implemented the CORDIC gain for hardware by using shift-and-add logic. To use a multiplier, set the ScalingMethod property to 'Multipliers'. To use shift-and-add logic, set this property to 'CSD'.

The System object accepts and returns a column vector of elements that represent samples in time. The input vector can contain up to 64 samples.

See Also

Blocks

  • Complex to Magnitude-Angle

Functions

  • cordicangle | cordiccart2pol | cordicabs | angle

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Magnitude and phase angle of complex signal (7)

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)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Magnitude and phase angle of complex signal (2024)

FAQs

How to calculate magnitude and phase angle of a complex number? ›

A complex number z = x+ jy in the second quadrant of the complex plane. −1(x/y). For the fourth quadrant, θ = tan−1(y/x) and θ = −π/2 − tan−1(x/y). Hence, the argument of any z in the strict lower half-plane is −π/2 − tan−1(x/y), and the argument of any z in the strict right half-plane is tan−1(y/x).

How do you find the magnitude and phase of a signal? ›

The magnitude is the square root of the sum of the squares of the real and imaginary parts. The phase is relative to the start of the time record or relative to a single-cycle cosine wave starting at the beginning of the time record. Single-channel phase measurements are stable only if the input signal is triggered.

What is magnitude and angle to complex? ›

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.

What is magnitude and phase angle? ›

The angular component periodic wave is known as the Phase Angle. It is a complex quantity measured by angular units like radians or degrees. A representation of any pure periodic wave is as follows. A∠θ, where A is the magnitude and θ represents the Phase Angle of the wave.

What is the formula for magnitude and angle? ›

MAGNITUDE AND DIRECTION OF A VECTOR

Given a position vector →v=⟨a,b⟩,the magnitude is found by |v|=√a2+b2. The direction is equal to the angle formed with the x-axis, or with the y-axis, depending on the application. For a position vector, the direction is found by tanθ=(ba)⇒θ=tan−1(ba), as illustrated in Figure 8.8.

How do you find the phase angle of a signal? ›

To calculate the phase angle, one typically measures the time difference between corresponding points on the voltage and current waveforms, then converts this time delay into an angle using the formula: phase angle = (time delay / period) * 360 degrees.

What is magnitude and phase response in signal and system? ›

The magnitude describes the strength of each frequency in the signal. The phase describes the sine/cosine phase of each frequency. The phase can also be thought of as the relative proportion of sines and cosines in the signal (i.e., a phase of zero contains only cosines and a phase of 90 degrees contains only sines).

What is the formula for phase calculation? ›

What Is the Phase Shift Formula?
  • Pi radians = 180o.
  • 3.14159265359 * 57.295779513o = 180o.
  • π = 3.14159265359.
  • 1 rad = 180o/3.14159265359 = 57.295779513o. ...
  • ps = phase shift in degrees.
  • p = wave period. ...
  • 360 × (0.002 ÷ 0.01) = a phase shift (ps) of 72 degrees. ...
  • 2 × pi × (td ÷ p)
Sep 17, 2020

How to calculate magnitude and phase angle of a complex number using Matlab? ›

[ mag , angle , validOut ] = magAngle( X , validIn ) converts a scalar or vector of complex values X into their component magnitude and phase angles.

What is the angle of a complex phase? ›

The angle or phase or argument of the complex number a + bj is the angle, measured in radians, from the point 1 + 0j to a + bj, with counterclockwise denoting positive angle. The angle of a complex number c = a + bj is denoted 6 c: 6 c = arctanb/a.

What is the phase and magnitude of a complex number? ›

The natural base constant e raised to any imaginary number produces a complex number with unit magnitude and angle varying with the parameter. Any complex number can be written in this form, where r and θ are real numbers specifying the magnitude and phase of the complex number. ex=1+x+x22! +x33!

What should my phase angle be? ›

To work out your Phase Angle, your BIA scale will use something called Impedance. Impedance is a ratio of your body's resistance and reactance when plotted and expressed in degrees. This is represented either using a graph or as an angle. Your phase angle should fall somewhere between 1 to 20 degrees.

How do you find the magnitude of a complex number? ›

Magnitude of Complex Number For a complex number z = x + jy, we define the magnitude, |z|, as follows: |z| = px2 + y2. The magnitude can be thought of as the distance a complex number z lies from the origin of the complex plane.

What is the formula for the phase angle? ›

If it is a series RC circuit, you can use: phase angle = -arctan(XC / R) . And for a series RL circuit, you can use: phase angle = arctan(XL / R) . You can calculate the phase angle with a calculator or spreadsheet, or use online tools or software that can simulate AC circuits and show you the phase angle graphically.

How to calculate phasor angle? ›

The easier way: Using phasors
  1. Z=R+jωL=1.2+j0.6=M∠ϕ
  2. M=√R2+(ωL)2=√1.22+0.62=1.34.
  3. ϕ=atan2(ωL,R)=atan2(6,1.2)=26.6o.
  4. Z=1.34∠26.6o.

Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 5779

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.