Accelerating the pace of engineering and science

# Documentation Center

• Trial Software
• Product Updates

# Sine, Cosine

Implement fixed-point sine or cosine wave using lookup table approach that exploits quarter wave symmetry

## Library

Lookup Tables (Sine block or Cosine block)

## Description

The Sine and Cosine block implements a sine and/or cosine wave in fixed point using a lookup table method that exploits quarter wave symmetry.

The Sine and Cosine block can output the following functions of the input signal, depending upon what you select for the Output formula parameter:

• sin(2πu)

• cos(2πu)

• exp(iu)

• sin(2πu) and cos(2πu)

You define the number of lookup table points in the Number of data points for lookup table parameter. The block implementation is most efficient when you specify the lookup table data points to be (2^n)+1, where n is an integer.

 Tip   To obtain meaningful block output, the block input values should fall within the range [0, 1). For input values that fall outside this range, the values are cast to an unsigned data type, where overflows wrap. For these out-of-range inputs, the block output might not be meaningful.

Use the Output word length parameter to specify the word length of the fixed-point output data type. The fraction length of the output is the output word length minus 2.

## Data Type Support

The Sine and Cosine block accepts signals of the following data types:

• Floating point

• Built-in integer

• Fixed point

• Boolean

The output of the block is a fixed-point data type.

For more information, see Data Types Supported by Simulink in the Simulink® documentation.

## Parameters and Dialog Box

Output formula

Select the signal(s) to output.

Number of data points for lookup table

Specify the number of data points to retrieve from the lookup table. The implementation is most efficient when you specify the lookup table data points to be (2^n)+1, where n is an integer.

Output word length

Specify the word length for the fixed-point data type of the output signal. The fraction length of the output is the output word length minus 2.

 Note:   The block uses double-precision floating-point values to construct lookup tables. Therefore, the maximum amount of precision you can achieve in your output is 53 bits. Setting the word length to values greater than 53 bits does not improve the precision of your output.
Internal rule priority for lookup table

Specify the internal rule for intermediate calculations. Select Speed for faster calculations. If you do, a loss of accuracy might occur, usually up to 2 bits.

## Examples

The sldemo_tonegen_fixptsldemo_tonegen_fixpt model shows how you can use the Sine block to implement a fixed-point sine wave.

For more information, see the model descriptionmodel description.

## Characteristics

 Direct Feedthrough Yes Sample Time Inherited from the driving block Scalar Expansion N/A Zero-Crossing Detection No

## See Also

Was this topic helpful?