Trigonometric Function - Specified trigonometric function on input - Simulink (original) (raw)

Specified trigonometric function on input

Libraries:
Simulink / Math Operations
HDL Coder / Math Operations
HDL Coder / HDL Floating Point Operations

Description

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

Supported Functions

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

Function Description Mathematical 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

CORDIC is an acronym for COordinate Rotation DIgital Computer. The Givens rotation-based CORDIC algorithm is one of the most hardware-efficient algorithms available because it requires only iterative shift-add operations. For more information, see More About. The block input has further requirements.

For more information on when you set Function tosin, cos, sincos, orcos + jsin and set the Approximation method to CORDIC, see Port_1.

This table summarizes what happens for an invalid input.

Block Usage Effect of Invalid Input
Simulation modes An error appears.
Generated code Undefined behavior occurs. Avoid relying on undefined behavior for generated code.

Lookup Approximation Method

For more information on when you set Function tosin, cos, sincos, or cos + jsin and set the Approximation method to Lookup, see Port_1.

Examples

expand all

This example shows how to use the Trigonometric Function block to compute the sine of a floating-point input. The output of the Trigonometric Function block has the same data type as the input because the input data type is floating-point and the Approximation method is none.

This example shows how to use the Trigonometric Function block to compute the CORDIC approximation of sincos for a fixed-point input signal.

The Trigonometric Function block parameters are:

When using the CORDIC approximation method, the input to the Trigonometric Function block must be in the range [-2pi,2pi). The output type of the Trigonometric Function block is fixdt(1,13,11) because the input is a fixed-point signal and the Approximation method is set to CORDIC. The output fraction length equals the input word length minus two.

This example compares the complex exponential output for two different configurations of the Trigonometric Function block.

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 minus two.

When the Approximation method is None, the input data type must be floating point. The output data type is the same as the input data type.

Limitations

Ports

Input

expand all

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

Functions Input Data Types
sincossincoscos + jsinatan2 Floating pointFixed point (only whenApproximation method isCORDIC orLookup)
tanasinacosatansinhcoshtanhasinhacoshatanh Floating point

CORDIC approximation fixed-point type propagations:

Input Data Type Function Output Data Type
Fixed point, signed or unsigned sin, cos,sincos, and cos + jsin fixdt(1,WL,WL - 2) where_WL_ is the input word lengthThis 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)

Lookup approximation fixed-point type propagations:

Input Data Type Function Output Data Type
Fixed point, signed sin, cos,sincos, cos + jsin, atan2 fixdt(1,WL,FL)
Fixed point, unsigned sin, cos,sincos, cos + jsin, atan2 fixdt(1,WL - 1,FL)

Dependencies

For CORDIC and Lookup approximations:

For more information, see Limitations.

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

Input the _x_-axis or real part of the function argument for atan2. When you setFunction 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 Identify Port Location on Rotated or Flipped Block for a description of the port order for various block orientations.)

Fixed-point input signals are supported only when you setApproximation method toCORDIC orLookup.

Dependencies

To enable this port, set Function toatan2.

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

Output

expand all

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

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

Sine of the input signal, in rad and rev.

Dependencies

To enable this port, set Function tosincos.

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

Cosine of the input signal, in rad and rev.

Dependencies

To enable this port, set Function tosincos.

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

Parameters

expand all

Algorithm

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

For more information on when you set Function tosin, cos,sincos, or cos + jsin and set the Approximation method toCORDIC, see Limitations.

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 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 iterative calculation.
Lookup Floating point (double and single) and fixed point with aBias value of0 and aSlope value of the power of 2 You want a fast, approximate lookup table implementation.

For more information on when you set Function tosin, cos,sincos, or cos + jsin and set the Approximation method toCORDIC, see Limitations.

Dependencies

Programmatic Use

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

When an input falls between breakpoint values, the block interpolates the output value using neighboring breakpoints. For more information on interpolation methods, see Interpolation Methods.

Programmatic Use

Block Parameter: InterpMethod
Type: character vector
Values: 'Linear point-slope' | 'Flat'
Default: 'Linear point-slope'

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

Dependencies

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

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 angle unit for lookup method asradian orrevolution.

Dependencies

To enable this parameter:

Programmatic Use

Block Parameter: AngleUnit
Type: character vector
Values: 'radian' | 'revolution'
Default: 'radian'

Specify the number of data points for lookup table as a scalar real number.

Dependencies

To enable this parameter:

Programmatic Use

Block Parameter: NumberOfDataPoints
Type: character vector
Values: scalar
Default: '16'

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 theFunction parameter real real real complex
complex complex error complex

Dependencies

Setting Approximation method toCORDIC disables this parameter.

Note

When Function isatan2, 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'

For acos andasin, select this check box to remove the protection against out-of-range inputs, which reduces redundancy.

Enabling this check box can eliminate redundancy if the input is already in range.

Dependencies

Setting Function toacos andasin enables this parameter.

Programmatic Use

Block Parameter: RemoveProtectionAgainstOutOfRangeInput
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. For more information, see Specify Sample Time.

Dependencies

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

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: SampleTime
Values: "-1" (default) | scalar or vector in quotes

Data Types

Data type for the lookup table, specified as:

For more information on setting data types, see Control Data Types of Signals.

Programmatic Use

Block Parameter: TableDataTypeStr
Type: string scalar or character vector
Values: Inherit: Inherit via input |single double fixdt(1,16,0) data type expression
Default: Inherit: Inherit via input

Select how you would like to specify the data type properties of theOutput data type. You can choose:

Dependencies

To enable this parameter, click >> at theOutput data type parameter.

Specify the Signedness for theOutput data type.

Dependencies

To enable this parameter, set Mode toFixed point.

Specify the Scaling for theOutput data type.

Dependencies

To enable this parameter, set Mode toFixed point.

Select the data type override mode for this signal.

For more information, see Specify Data Types Using Data Type Assistant in the Simulink® documentation.

Tips

The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.

Dependencies

To enable this parameter, click the Show data type assistant button, and set Mode to Built in or Fixed point.

Specify the bit size of the word that holds the quantized integer. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set Mode toFixed point.

Specify fraction length for fixed-point data type as a positive or negative integer. For more information, see Specifying a Fixed-Point Data Type.

Dependencies

To enable this parameter, set:

Block Characteristics

Data Types double | fixed pointa half integera single
Direct Feedthrough yes
Multidimensional Signals yes
Variable-Size Signals yes
Zero-Crossing Detection no
a This block supports fixed-point and base integer data types for 'Approximation method' CORDIC.

More About

expand all

CORDIC is an acronym for coordinate rotation digital computer. The Givens rotation-based CORDIC algorithm is one of the most hardware-efficient algorithms available because it requires only iterative shift-add 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 increases the expense of the computation and adds latency.

References

[1] Volder, Jack E., “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers EC-8 (1959); 330–334.

[2] Andraka, Ray “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,” Proceedings of the Spring Joint Computer Conference, May 18-20, 1971: 379–386.

[4] Schelin, Charles W., “Calculator Function Approximation,” The American Mathematical Monthly 90, no. 5 (1983): 317–325.

Extended Capabilities

expand all

Not all compilers support the asinh, acosh, and atanh functions. If you use a compiler that does not support those functions, a warning appears and the generated code fails to link.

HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.

HDL Architecture

To generate HDL code from the blocks that use fixed-point data, set Architecture to Cordic or LUT. This table shows the functions the block supports for these setting:

Block Parameters HDL Block Properties Supported Functions
Set Approximation method toCORDIC, Number of data Points to any scalar real number. Set Architecture toCordic. sincossincoscos+jsinatan2
Set Approximation method toLookup,Interpolation method toFlat, Angle Unit torevolution, and Number of data Points to any scalar real number. Set Architecture toLUT. sincossincoscos+jsin

To generate HDL code for all functions of the block that use floating-point data, set theApproximation method block parameter tonone, and the Output signal type parameter to auto orreal or complex. Additionally, set the Architecture parameter in the HDL Block Properties to Trigonometric.

This block has multi-cycle implementations that introduce additional latency in the generated code. To see the added latency, view the generated model or validation model. See Generated Model and Validation Model (HDL Coder).

The latency calculation depends on the word length andLatencyStrategy settings. To view the latency calculation for fixed-point data types, see:

HDL Block Properties

General
ConstrainedOutputPipeline Number of registers to place at the outputs by moving existing delays within your design. Distributed pipelining does not redistribute these registers. The default is0. For more details, see ConstrainedOutputPipeline (HDL Coder).
InputPipeline Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see InputPipeline (HDL Coder).
OutputPipeline Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see OutputPipeline (HDL Coder).
LatencyStrategy To enable this property for fixed-point types, setFunction as sin,cos, sincos,cos+jsin, or atan2 and Approximation method asCORDIC. Specify whether to map the blocks in your design to MAX,Min, CUSTOM, orZERO latency for fixed-point and floating-point types. The default isMAX. See also LatencyStrategy (HDL Coder).
CustomLatency To enable this property for fixed-point types, setFunction as sin,cos, sincos,cos+jsin, or atan2 and Approximation method asCORDIC. WhenLatencyStrategy is set toCUSTOM, use this property to specify a custom latency value between ZERO andMAX for fixed-point types. See alsoLatencyStrategy (HDL Coder).
IterationsPerPipeline To enable this property for fixed-point types, setFunction as sin,cos, sincos,cos+jsin, or atan2 and Approximation method asCORDIC. When you setLatencyStrategy toCustom(PerIterations), use this setting to specify the number of iterations per pipeline stages. For more information, see Atan2 (HDL Coder).
Native Floating Point
InputRangeReduction Use this property for the sin, cos,sincos, cos+jsin, and atan2 functions. If your input range is unbounded, enable this property for HDL Coder to insert additional logic to reduce the range of inputs to [-pi, pi]. See also InputRangeReduction (HDL Coder).
HandleDenormals Specify whether you want HDL Coder to insert additional logic to handle denormal numbers in your design. Denormal numbers are numbers that have magnitudes less than the smallest floating-point number that can be represented without leading zeros in the mantissa. The default isinherit. See also HandleDenormals (HDL Coder).
LatencyStrategy Specify whether to map the blocks in your design toinherit, Max, Min, or Zero for the floating-point operator. The default isinherit. See also LatencyStrategy (HDL Coder).
MultiplyStrategy Use this property for the sin, cos,sincos, cos+jsin, and atan2 functions. The default isinherit. Specify whether you want to use FullMultiplier orPartMultiplierPartAddShift. See alsoMantissaMultiplyStrategy (HDL Coder).

Restrictions

This block supports fixed-point and base integer data types when you set theFunction to sin,cos, sincos,cos + jsin, or atan2 and set theApproximation method toCORDIC.

Version History

Introduced before R2006a