Skip to Main Content Skip to Search
Product Documentation

Trigonometric Function - Specified trigonometric function on input

Library

Math Operations

Description

Supported Functions

The Trigonometric Function block performs common trigonometric functions. You can select one of the following functions from the Function parameter list.

FunctionDescriptionMathematical ExpressionMATLAB Equivalent
sin

Sine of the input

sin(u)

sin
cos

Cosine of the input

cos(u)

cos
tan

Tangent of the input

tan(u)

tan
asin

Inverse sine of the input

asin(u)

asin
acos

Inverse cosine of the input

acos(u)

acos
atan

Inverse tangent of the input

atan(u)

atan
atan2

Four-quadrant inverse tangent of the input

atan2(u)

atan2
sinh

Hyperbolic sine of the input

sinh(u)

sinh
cosh

Hyperbolic cosine of the input

cosh(u)

cosh
tanh

Hyperbolic tangent of the input

tanh(u)

tanh
asinh

Inverse hyperbolic sine of the input

asinh(u)

asinh
acosh

Inverse hyperbolic cosine of the input

acosh(u)

acosh
atanh

Inverse hyperbolic tangent of the input

atanh(u)

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:

Block Appearance for the atan2 Function

If you select the atan2 function, the block shows two inputs. The first input is the y-axis or imaginary part of the function argument. The second input is the x-axis 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.)

Block Appearance for the sincos Function

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.

Effect of Out-of-Range Input on CORDIC Approximations

If you use the CORDIC approximation method (see Definitions), the block input has the following restrictions:

The following table summarizes what happens for an out-of-range input.

Block UsageEffect of Out-of-Range Input
SimulationAn error appears.
Generated codeUndefined behavior occurs.
Accelerator modes

Ensure that you use an in-range input for the Trigonometric Function block when you use the CORDIC approximation, which is available for the sin, cos, sincos, and cos + jsin functions. Avoid relying on undefined behavior for generated code or Accelerator modes.

Definitions

CORDIC

CORDIC is an acronym for COordinate Rotation DIgital Computer. The Givens rotation-based CORDIC algorithm is among one of the most hardware-efficient algorithms available because it requires only iterative shift-add operations (see [1], [2]) 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, and 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.

Data Type Support

The block accepts input signals of the following data types:

FunctionsInput Data Types
  • sin

  • cos

  • sincos

  • cos + jsin

  • Floating point

  • Fixed point (only when Approximation method is CORDIC)

  • tan

  • asin

  • acos

  • atan

  • atan2

  • sinh

  • cosh

  • tanh

  • asinh

  • acosh

  • atanh

  • Floating point

The block output data type depends on the input data type and your selection for Approximation method:

Input Data TypeApproximation MethodOutput Data Type

Floating point

None or CORDIC

Same as input

Fixed point

CORDIC

fixdt(1, WL, WL – 2) where WL is the input word length

This fixed-point type provides the best precision for the CORDIC algorithm.

The CORDIC approximation is available for the sin, cos, sincos, and cos + jsin functions.

Complex input signals are supported for all functions in this block, except atan2. The block output is real or complex, depending on your selection for Output signal type. This parameter is not available when you use the CORDIC approximation to compute block output. For CORDIC approximations, the output must be:

Parameters and Dialog Box

Function

Specify the trigonometric function. The name of the function on the block icon changes to match your selection.

Approximation method

Specify the type of approximation for computing output. This parameter appears only when you set Function to sin, cos, sincos, or cos + jsin.

Approximation MethodData Types SupportedWhen 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, the block icon changes:

FunctionBlock Icon
sin

cos

sincos

cos + jsin

When you use the CORDIC approximation, follow these guidelines:

  • For signed fixed-point types, the input angle must fall within the range [–2π, 2π) radians.

  • For unsigned fixed-point types, the input angle must fall within the range [0, 2π) radians.

Number of iterations

Specify the number of iterations to perform the CORDIC algorithm. The default value is 11.

  • When the block input uses a floating-point data type, the number of iterations can be a positive integer.

  • When the block input is a fixed-point 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, or cos + jsin.

  • You set Approximation method to CORDIC.

Output signal type

Specify the output signal type of the Trigonometric Function block as auto, real, or complex.

FunctionInput Signal TypeOutput Signal Type
AutoRealComplex
Any selection for the Function parameterrealrealrealcomplex
complexcomplexerrorcomplex

    Note   When Function is atan2, complex input signals are not supported for simulation or code generation.

Setting Approximation method to CORDIC disables this parameter.

Sample time (-1 for inherited)

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time in the Simulink documentation for more information.

Examples

sin Function with Floating-Point Input

Suppose that you have the following model:

The key block parameters for the Constant block are:

ParameterSetting
Constant value1
Output data typeInherit: Inherit from 'Constant value'

The block parameters for the Trigonometric Function block are:

ParameterSetting
Functionsin
Approximation methodNone
Output signal typeauto
Sample time-1

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.

sincos Function with Fixed-Point Input

Suppose that you have the following model:

The key block parameters for the Constant block are:

ParameterSetting
Constant value

1

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 fixed-point type.

Output data typefixdt(1,13,5)

The block parameters for the Trigonometric Function block are:

ParameterSetting
Functionsincos
Approximation methodCORDIC
Number of iterations11
Sample time-1

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.

Block Behavior for Complex Exponential Output

The following model compares the complex exponential output for the two different approximation methods:

The key block parameters for the Constant blocks are:

BlockParameterSetting
ConstantConstant value[-pi/2 0 pi]
Output data typefixdt(1,16,2)
Constant1Constant value[-pi/2 0 pi]
Output data typedouble

The block parameters for the Trigonometric Function blocks are:

BlockParameterSetting
Approximation = 'CORDIC'Functioncos + jsin
Approximation methodCORDIC
Number of iterations11
Sample time-1
Approximation = 'None'Functioncos + jsin
Approximation methodNone
Sample time-1

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.

Digital Waveform Generation: Sine Wave Approximation

To learn how to generate a digital waveform using a CORDIC sine approximation, see the description for the sldemo_tonegen_fixpt model.

Characteristics

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

Zero-Crossing Detection

No

References

[1] Volder, J.E. "The CORDIC Trigonometric Computing Technique," IRE Transactions on Electronic Computers. Vol. EC-8, 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.

See Also

Math Function, Sqrt

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS