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. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Trigonometric Function

Specified trigonometric function on input

  • Library:
  • Simulink / Math Operations

    HDL Coder / Math Operations

Description

The Trigonometric Function block performs common trigonometric functions and outputs the result in rad.

Supported Functions

You can select one of these functions from the Function parameter list.

FunctionDescriptionMathematical Expression MATLAB® 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

CORDIC Approximation Method

If you use the CORDIC approximation method (see Definitions), the block input has some further requirements.

When you set Function to sin, cos, sincos, or cos + jsin, and set the Approximation method to CORDIC, the block has these limitations:

  • When you use signed fixed-point types, the input angle must fall within the range [–2π, 2π) rad.

  • When you use unsigned fixed-point types, the input angle must fall within the range [0, 2π) rad.

When you set Function to atan2 and the Approximation method to CORDIC, the block has these limitations:

  • 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 fixed-point types, the word length must be 126 or less.

  • When you use unsigned fixed-point types, the word length must be 125 or less.

This table summarizes what happens for an invalid input.

Block UsageEffect of Invalid Input
SimulationAn error appears.
Generated codeUndefined behavior occurs. Avoid relying on undefined behavior for generated code or accelerator modes.
Accelerator modes

Ports

Input

expand all

Input specified as a scalar, vector, or matrix. The block accepts input signals of the following data types:

FunctionsInput Data Types
  • sin

  • cos

  • sincos

  • cos + jsin

  • atan2

  • Floating point

  • Fixed point (only when Approximation method is CORDIC)

  • tan

  • asin

  • acos

  • atan

  • sinh

  • cosh

  • tanh

  • asinh

  • acosh

  • atanh

  • Floating point

Dependencies

  • When you set Function to atan2, the block shows two input ports. The first input (Port_1) is the y-axis or imaginary part of the function argument. The second input (Port_2) is the x-axis or real part of the function argument.

  • You can use floating-point 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 TypeApproximation MethodOutput Data Type

    Floating point

    None

    Depends on your selection for Output signal type. Options are auto (same data type as input), real, or complex.

    Floating point

    CORDIC

    Same as input. Output signal type is not available when you use the CORDIC approximation method to compute the block output.

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.

Limitations

Complex input signals are supported for all functions in this block, except atan2.

You can use fixed-point 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 fixed-point input is signed or unsigned.

Input Data TypeFunctionOutput Data Type

Fixed point, signed or unsigned

sin, cos, sincos, and cos + jsin

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

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

Fixed point, signed

atan2

fixdt(1, WL, WL – 3)

Fixed point, unsigned

atan2

fixdt(1, WL, WL – 2)

When you set Function to sin, cos, sincos, or cos + jsin, and set the Approximation method to CORDIC, the block has these limitations:

  • When you use signed fixed-point types, the input angle must fall within the range [–2π, 2π) rad.

  • When you use unsigned fixed-point types, the input angle must fall within the range [0, 2π) rad.

When you set Function to atan2 and the Approximation method to CORDIC, the block has these limitations:

  • 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 fixed-point types, the word length must be 126 or less.

  • When you use unsigned fixed-point types, the word length must be 125 or less.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Input the x-axis or real part of the function argument for atan2. When you set Function to atan2, the block shows two input ports. The first input (Port_1) is the y-axis or imaginary part of the function argument. The second input (Port_2) is the x-axis or real part of the function argument. (See Port Location After Rotating or Flipping for a description of the port order for various block orientations.)

Dependencies

To enable this port, set Function to atan2.

Limitations

  • Fixed-point input signals are supported only when you set Approximation method to CORDIC.

  • When you set Function to atan2 and Approximation method to CORDIC:

    • 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 fixed-point types, the word length must be 126 or less.

    • When you use unsigned fixed-point types, the word length must be 125 or less.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Output

expand all

Result of applying the specified trigonometric function to one or more inputs in rad. Each function supports:

  • Scalar operations

  • Element-wise vector and matrix operations

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Sine of the input signal, in rad.

Dependencies

To enable this port, set Function to sincos.

Limitations

Fixed-point input signals are supported only when you set Approximation method to CORDIC.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Cosine of the input signal, in rad.

Dependencies

To enable this port, set Function to sincos.

Limitations

Fixed-point input signals are supported only when you set Approximation method to CORDIC.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Parameters

expand all

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

Limitations

When you set Function to sin, cos, sincos, or cos + jsin, and set the Approximation method to CORDIC, the block has these limitations:

  • When you use signed fixed-point types, the input angle must fall within the range [–2π, 2π) rad.

  • When you use unsigned fixed-point types, the input angle must fall within the range [0, 2π) rad.

When you set Function to atan2 and the Approximation method to CORDIC, the block has these limitations:

  • 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 fixed-point types, the word length must be 126 or less.

  • When you use unsigned fixed-point types, the word length must be 125 or less.

Programmatic Use

Block Parameter: Operator
Type: character vector
Values: 'sin' | 'cos' | 'tan' | 'asin' | 'acos' | 'atan' | 'atan2' | 'sinh' | 'cosh' | 'tanh' | 'asinh' | 'acosh' | 'atanh' | 'sincos' | 'cos + jsin'
Default: 'sin'

Specify the type of approximation for computing output.

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 and enlarge the block from the default size, the block icon changes:

FunctionBlock Icon
sin

cos

sincos

cos + jsin

atan2

Dependencies

To enable this parameter, set Function to sin, cos, sincos, cos + jsin, or atan2.

To use fixed-point input signals, you must set Approximation method to CORDIC.

Limitations

When you set Function to sin, cos, sincos, or cos + jsin, and set the Approximation method to CORDIC, the block has these limitations:

  • When you use signed fixed-point types, the input angle must fall within the range [–2π, 2π) rad.

  • When you use unsigned fixed-point types, the input angle must fall within the range [0, 2π) rad.

When you set Function to atan2 and the Approximation method to CORDIC, the block has these limitations:

  • 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 fixed-point types, the word length must be 126 or less.

  • When you use unsigned fixed-point types, the word length must be 125 or less.

Programmatic Use

Block Parameter: ApproximationMethod
Type: character vector
Values: 'None' | 'CORDIC'
Default: 'None'

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.

Dependencies

To enable this parameter, you must set the Function and Approximation method parameters as follows:

  • Set Function to sin, cos, sincos, cos + jsin, or atan2.

  • Set Approximation method to CORDIC.

Programmatic Use

Block Parameter: NumberOfIterations
Type: character vector
Values: positive integer, less than or equal to word length of fixed-point input
Default: '11'

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 parameter realrealrealcomplex
complexcomplexerrorcomplex

Dependencies

Setting Approximation method to CORDIC disables this parameter.

Note

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

Programmatic Use

Block Parameter: OutputSignalType
Type: character vector
Values: 'auto' | 'real' | 'complex'
Default: 'auto'

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

Dependencies

This parameter is not visible unless it is explicitly set to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar
Default: '-1'

Block Characteristics

Data Types

double | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

More About

expand all

References

[1] Volder, JE. “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers EC-8 (1959); 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): 191–200.

[3] Walther, J.S. “A Unified Algorithm for Elementary Functions.” Hewlett-Packard Company, Palo Alto. Spring Joint Computer Conference (1971): 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 90, no. 5 (1983): 317–325.

Extended Capabilities

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Introduced before R2006a