atan2
Four-quadrant inverse tangent of fixed-point values
Syntax
Description
Examples
Use the atan2
function to calculate the arctangent of unsigned and signed fixed-point input values.
Unsigned Input Values
This example uses unsigned, 16-bit word length values.
y = fi(0.125,0,16); x = fi(0.5,0,16); z = atan2(y,x)
z = 0.2450 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 15
Signed Input Values
This example uses signed, 16-bit word length values.
y = fi(-0.1,1,16); x = fi(-0.9,1,16); z = atan2(y,x)
z = -3.0309 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13
Input Arguments
y-coordinates, specified as a scalar, vector, matrix, or multidimensional array.
y
and x
can be real-valued, signed or
unsigned scalars, vectors, matrices, or N
-dimensional arrays
containing fixed-point angle values in radians. The inputs y
and
x
must be the same size. If they are not the same size, at least
one input must be a scalar value. Valid data types of y
and
x
are:
fi
singlefi
doublefi
fixed-point with binary point scalingfi
scaled double with binary point scaling
Data Types: fi
x-coordinates, specified as a scalar, vector, matrix, or multidimensional array.
y
and x
can be real-valued, signed or
unsigned scalars, vectors, matrices, or N
-dimensional arrays
containing fixed-point angle values in radians. The inputs y
and
x
must be the same size. If they are not the same size, at least
one input must be a scalar value. Valid data types of y
and
x
are:
fi
singlefi
doublefi
fixed-point with binary point scalingfi
scaled double with binary point scaling
Data Types: fi
Output Arguments
Four-quadrant arctangent, returned as a scalar, vector, matrix, or multidimensional array.
z
is the four-quadrant arctangent of y
and
x
. The numerictype
of z
depends on the signedness of y
and x
:
If either
y
orx
is signed, thenz
is a signed, fixed-point number in the range [–pi,pi]. It has a 16-bit word length and 13-bit fraction length (numerictype(1,16,13)
).If both
y
andx
are unsigned, thenz
is an unsigned, fixed-point number in the range [0,pi/2]. It has a 16-bit word length and 15-bit fraction length (numerictype(0,16,15)
).
The output, z
, is always associated with the default
fimath
.
More About
The four-quadrant arctangent is defined as follows, with respect to the
atan
function:
Algorithms
The atan2
function computes the four-quadrant arctangent of
fixed-point inputs using an 8-bit lookup table as follows:
Divide the input absolute values to get an unsigned, fractional, fixed-point, 16-bit ratio between 0 and 1. The absolute values of y and x determine which value is the divisor.
The signs of the
y
andx
inputs determine in what quadrant their ratio lies. The input with the larger absolute value is used as the denominator, thus producing a value between 0 and 1.Compute the table index, based on the 16-bit, unsigned, stored integer value:
Use the 8 most-significant bits to obtain the first value from the table.
Use the next-greater table value as the second value.
Use the 8 least-significant bits to interpolate between the first and second values using nearest neighbor linear interpolation. This interpolation produces a value in the range [0, pi/4).
Perform octant correction on the resulting angle, based on the values of the original
y
andx
inputs.
This arctangent calculation is accurate only to within the top 16 most-significant bits of the input.
The atan2
function ignores and discards any fimath
attached to the inputs. The output, z
, is always associated with the
default fimath
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2012a
See Also
atan2
| sin
| angle
| cos
| cordicatan2
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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
- United Kingdom (English)