Sine
Implement fixed-point sine or cosine wave using lookup table approach that exploits quarter wave symmetry
Libraries:
Simulink /
Lookup Tables
Alternative Configurations of Sine Block:
Cosine
Description
The Sine and Cosine blocks implement a sine wave, cosine wave, or both in fixed point using a lookup table method that exploits quarter wave symmetry. The 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(j2πu)
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.
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.
Examples
Digital Waveform Generation: Approximate a Sine Wave
Design and evaluate a sine wave data table for use in digital waveform synthesis applications in embedded systems and arbitrary waveform generation instruments.
Ports
Input
u — Input signal to implement as fixed-point sine or cosine wave
real-valued signal
Input signal, u, specified as a real-valued scalar, vector, or matrix.
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.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Output
sin(2*pi*u) — Fixed-point sine wave
real-valued fixed-point signal
Fixed-point sine wave, implemented using a lookup table approach.
Dependencies
This port is enabled when the Output formula
is set to sin(2*pi*u)
or
sin(2*pi*u) and cos(2*pi*u)
.
Data Types: fixed point
cos(2*pi*u) — Fixed-point cosine wave
real-valued fixed-point signal
Fixed-point cosine wave, implemented using a lookup table approach.
Dependencies
This port is enabled when the Output formula
is set to cos(2*pi*u)
or
sin(2*pi*u) and cos(2*pi*u)
.
Data Types: fixed point
exp(j*2*pi*u) — exp(j*2*pi*u)
complex-valued fixed-point signal
exp(j*2*pi*u)
,
implemented using a lookup table approach.
Dependencies
This port is enabled when the Output formula
is set to exp(j*2*pi*u)
.
Data Types: fixed point
Parameters
Output formula — Select the signals to output
cos(2*pi*u)
| sin(2*pi*u)
| exp(j*2*pi*u)
| sin(2*pi*u) and cos(2*pi*u)
Select the signals to output.
For the Sine block, the default value of this parameter is
sin(2*pi*u)
.
For the Cosine block, the default value of this parameter
is cos(2*pi*u)
.
Programmatic Use
Block Parameter:
Formula |
Values:
'sin(2*pi*u)' | 'cos(2*pi*u)' | 'exp(j*2*pi*u)' |
'sin(2*pi*u) and cos(2*pi*u)' |
Number of data points for lookup table — Specify the number of data points to retrieve from the lookup table
(2^5)+1
(default) | integer greater than or equal to 2
The implementation is most efficient when you specify the lookup table
data points to be (2^n)+1
, where
n is an integer. To be compatible with the
Output word length parameter, the Number
of data points for lookup table must be less than or equal to (2^(Output word
length-2)+1).
Programmatic Use
Block Parameter:
NumDataPoints |
Type: scalar |
Value: integer greater than or equal to 2 |
Default:
'(2^5)+1' |
Output word length — Specify the word length for the fixed-point data type of the output signal
16
(default) | integer from 2 to 53
The fraction length of the output is the output word length minus 2. To be compatible with the Number of data points for lookup table parameter, (2^(Output word length - 2) +1) must be greater than or equal to Number of data points for lookup table.
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.
Programmatic Use
Block Parameter:
OutputWordLength |
Type: scalar |
Value: integer from 2 to 53 |
Default:
'16' |
Internal rule priority for lookup table — Specify the internal rule for intermediate calculations
Speed
(default) | Precision
Select Speed
for faster calculations. If you
do, a loss of accuracy might occur, usually up to 2 bits.
Programmatic Use
Block Parameter:
InternalRulePriority |
Values:
'Speed' | 'Precision' |
Default:
'Speed' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Alternative Configurations
Cosine — Implement fixed-point cosine wave using lookup table approach that exploits quarter wave symmetry
The Cosine block sets Output formula
to cos(2*pi*u)
.
Libraries:
Simulink /
Lookup Tables
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
The HDL code implements Cosine and Sine blocks by using the quarter-wave lookup table that you specify in the Simulink block parameters.
To avoid generating a division operator
(/
) in the HDL code, for Number of data points
for lookup table, enter
(2^
.
n
)+1n
is an integer.
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 is
|
InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
If you use Intel® MAX 10 device, to map the lookup table to RAM, add this Tcl command when creating the project in the Quartus tool:
set_global_assignment -name INTERNAL_FLASH_UPDATE_MODE "SINGLE IMAGE
WITH ERAM"
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced before R2006a
See Also
Sine Wave | Trigonometric Function | Sine HDL Optimized, Cosine HDL Optimized (HDL Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)