Specified trigonometric function on input
Math Operations
The Trigonometric Function block performs common trigonometric functions. You can select one of the following functions from the Function parameter list.
Function  Description  Mathematical Expression  MATLAB^{®} Equivalent 

sin  Sine of the input 
 sin 
cos  Cosine of the input 
 cos 
tan  Tangent of the input 
 tan 
asin  Inverse sine of the input 
 asin 
acos  Inverse cosine of the input 
 acos 
atan  Inverse tangent of the input 
 atan 
atan2  Fourquadrant inverse tangent of the input 
 atan2 
sinh  Hyperbolic sine of the input 
 sinh 
cosh  Hyperbolic cosine of the input 
 cosh 
tanh  Hyperbolic tangent of the input 
 tanh 
asinh  Inverse hyperbolic sine of the input 
 asinh 
acosh  Inverse hyperbolic cosine of the input 
 acosh 
atanh  Inverse hyperbolic tangent of the input 
 atanh 
sincos  Sine of the input; cosine of the input  —  — 
cos + jsin  Complex exponential of the input  —  — 
The block output is the result of applying the function to one or more inputs in radians. Each function supports:
Scalar operations
Elementwise vector and matrix operations
Note:
Not all compilers support the 
If you select the atan2
function, the block
shows two inputs. The first input is the yaxis
or imaginary part of the function argument. The second input is the xaxis
or real part of the function argument. (See How to Rotate a Block in the Simulink^{®} documentation
for a description of the port order for various block orientations.)
If you select the sincos
function, the block
shows two outputs. The first output is the sine of the function argument,
and the second output is the cosine of the function argument.
CORDIC is an acronym for COordinate Rotation DIgital Computer. The Givens rotationbased CORDIC algorithm is one of the most hardwareefficient algorithms available because it requires only iterative shiftadd 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 also increases the expense of the computation and adds latency.
The block accepts input signals of the following data types:
Functions  Input Data Types 





Complex input signals are supported for all functions in this
block, except atan2
.
You can use floatingpoint input signals when you set Approximation
method to None
or CORDIC
.
However, the block output data type depends on which of these approximation
method options you choose.
Input Data Type  Approximation Method  Output Data Type 

Floating point  None  Depends on your selection for Output signal
type. Options are 
Floating point  CORDIC  Same as input. Output signal type is not available when you use the CORDIC approximation method to compute the block output. 
You can use fixedpoint input signals only when Approximation
method is set to CORDIC
. The
CORDIC approximation is available for the sin
, cos
, sincos
, cos
+ jsin
, and atan2
functions. For the atan2
function,
the relationship between input and output data types depends also
on whether the fixedpoint input is signed or unsigned.
Input Data Type  Function  Output Data Type 

Fixed point, signed or unsigned  sin , cos , sincos ,
and cos + jsin 
This fixedpoint type provides the best precision for the CORDIC algorithm. 
Fixed point, signed  atan2 

Fixed point, unsigned  atan2 

For CORDIC approximations:
Input must be real for the sin
, cos
, sincos
, cos
+ jsin
, and atan2
functions.
Output is real for the sin
, cos
, sincos
,
and atan2
functions.
Output is complex for the cos + jsin
function.
If you use the CORDIC approximation method (see Definitions), the block input has some further requirements.
For the sin
, cos
, sincos
,
and cos + jsin
functions:
When you use signed fixedpoint types, the input angle must fall within the range [–2π, 2π) radians.
When you use unsigned fixedpoint types, the input angle must fall within the range [0, 2π) radians.
For the atan2
function:
Inputs must be the same size, or at least one value must be a scalar value.
Both inputs must have the same data type.
When you use signed fixedpoint types, the word length
must be 126
or less.
When you use unsigned fixedpoint types, the word
length must be 125
or less.
This table summarizes what happens for an invalid input.
Block Usage  Effect of Invalid Input 

Simulation  An error appears. 
Generated code  Undefined behavior occurs. Avoid relying on undefined behavior for generated code or Accelerator modes. 
Accelerator modes 
Specify the trigonometric function. The name of the function on the block icon changes to match your selection.
Specify the type of approximation for computing output. This
parameter appears only when you set Function to sin
, cos
, sincos
, cos
+ jsin
, or atan2
.
Approximation Method  Data Types Supported  When 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. 
If you select CORDIC
and enlarge
the block from the default size, the block icon changes:
Function  Block Icon 

sin 

cos 

sincos 

cos + jsin 

atan2 

Specify the number of iterations to perform the CORDIC algorithm. The default value is 11.
When the block input uses a floatingpoint data type, the number of iterations can be a positive integer.
When the block input is a fixedpoint data type, the number of iterations cannot exceed the word length.
For example, if the block input is fixdt(1,16,15)
,
the word length is 16. In this case, the number of iterations cannot
exceed 16.
This parameter appears when both of the following conditions hold:
You set Function to sin
, cos
, sincos
, cos
+ jsin
, or atan2
.
You set Approximation method to CORDIC
.
Specify the output signal type of the Trigonometric Function
block as auto
, real
, or complex
.
Function  Input Signal Type  Output Signal Type  

Auto  Real  Complex  
Any selection for the Function parameter  real  real  real  complex 
complex  complex  error  complex 
Note:
When Function is 
Setting Approximation method to CORDIC
disables
this parameter.
Note:
This parameter is not visible in the block dialog box unless
it is explicitly set to a value other than 
Suppose that you have the following modelmodel:
The key block parameters for the Constant block are:
Parameter  Setting 

Constant value  1 
Output data type  Inherit: Inherit from 'Constant value' 
The block parameters for the Trigonometric Function block are:
Parameter  Setting 

Function  sin 
Approximation method  None 
Output signal type  auto 
The output type of the Trigonometric Function block is the same
as the input because the input type is floating point and Approximation
method is None
.
Suppose that you have the following modelmodel:
The key block parameters for the Constant block are:
Parameter  Setting 

Constant value 
This value must fall within the range [–2π, 2π) because the Trigonometric Function block uses the CORDIC algorithm and the block input uses a signed fixedpoint type. 
Output data type  fixdt(1,13,5) 
The block parameters for the Trigonometric Function block are:
Parameter  Setting 

Function  sincos 
Approximation method  CORDIC 
Number of iterations  11 
The output type of the Trigonometric Function block is fixdt(1,13,11)
because
the input type is fixed point and Approximation method is CORDIC
.
The output fraction length equals the input word length – 2.
The following modelmodel compares the complex exponential output for the two different approximation methods:
The key block parameters for the Constant blocks are:
Block  Parameter  Setting 

Constant  Constant value  [pi/2 0 pi] 
Output data type  fixdt(1,16,2)  
Constant1  Constant value  [pi/2 0 pi] 
Output data type  double 
The block parameters for the Trigonometric Function blocks are:
Block  Parameter  Setting 

Approximation = 'CORDIC'  Function  cos + jsin 
Approximation method  CORDIC  
Number of iterations  11  
Approximation = 'None'  Function  cos + jsin 
Approximation method  None 
When the Approximation method is CORDIC
,
the input data type can be fixed point, in this case: fixdt(1,16,2)
.
The output data type is fixdt(1,16,14)
because
the output fraction length equals the input word length – 2.
When the Approximation method is None
,
the input data type must be floating point. The output data type is
the same as the input.
To learn how to generate a digital waveform using a CORDIC sine
approximation, see the descriptiondescription for
the sldemo_tonegen_fixptsldemo_tonegen_fixpt
model.
Direct Feedthrough  Yes 
Sample Time  Inherited from the driving block 
Scalar Expansion  Yes, of the input when the function requires two inputs 
Dimensionalized  Yes 
Multidimensionalized  Yes 
ZeroCrossing Detection  No 
[1] Volder, JE. "The CORDIC Trigonometric Computing Technique." IRE Transactions on Electronic Computers. Vol. EC8, September 1959, pp. 330–334.
[2] Andraka, R. "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, pp. 191–200.
[3] Walther, J.S. "A Unified Algorithm for Elementary Functions." HewlettPackard Company, Palo Alto. Spring Joint Computer Conference, 1971, pp. 379–386. (from the collection of the Computer History Museum). www.computer.org/csdl/proceedings/afips/1971/5077/00/50770379.pdf
[4] Schelin, Charles W. "Calculator Function Approximation." The American Mathematical Monthly. Vol. 90, No. 5, May 1983, pp. 317–325.