Sine Wave
Generate continuous or discrete sine wave
Libraries:
DSP System Toolbox /
Sources
DSP System Toolbox HDL Support /
Sources
Description
The Sine Wave block generates a multichannel real or complex sinusoidal signal, with independent amplitude, frequency, and phase in each output channel. The block supports floating point and signed fixed-point data types.
The block generates a real sinusoidal signal when you set the Output
complexity parameter to Real. The real
sinusoidal output is defined by an expression of the type
where you specify A in the Amplitude parameter, f in hertz in the Frequency parameter, and ϕ in radians in the Phase offset parameter.
The block generates a complex exponential signal when you set the Output
complexity parameter to Complex. This complex
exponential signal is defined by an expression of the type
Generating Multichannel Outputs
For both real and complex sinusoids, the Amplitude, Frequency, and Phase offset parameter values (A, f, and ϕ) can be scalars or length-N vectors, where N is the desired number of channels in the output. When you specify at least one of these parameters as a length-N vector, scalar values specified for the other parameters are applied to every channel.
For example, to generate the three-channel output containing the following real sinusoids, set the block parameters as shown:
Output complexity =
RealAmplitude =
[1 2 3]Frequency =
[1000 500 250]Phase offset =
[0 0 pi/2]
Examples
This example compares the different methods of generating sample-based sine waves from the Sine Wave block in DSP System Toolbox.

This example compares the different methods of generating frame-based sine waves from the Sine Wave block in DSP System Toolbox™.

Ports
Output
Output a sinusoidal signal as a scalar or vector. For more information about output complexity, see Description. For information about multichannel support, see Generating Multichannel Outputs.
Tip
To output fixed-point data types, you must set Sample
mode to Discrete and
Computation method to Table
lookup.
Data Types: single | double | fixed point
Complex Number Support: Yes
Parameters
Main
A length-N vector containing the amplitudes of the sine waves in each of N output channels, or a scalar to be applied to all N channels. The vector length must be the same as that specified for the Frequency and Phase offset parameters.
Tip
This parameter is tunable (Simulink) only when the Computation
method is Trigonometric
fcn or
Differential.
Tunable: Yes
A length-N vector containing frequencies, in hertz, of the sine waves in each of N output channels, or a scalar to be applied to all N channels. The vector length must be the same as that specified for the Amplitude and Phase offset parameters. You can specify positive, zero, or negative frequencies.
Tip
This parameter is tunable (Simulink) when you set:
Solver Type to
Fixed-step.Sample mode to
Continuous.Sample mode to
Discreteand Computation method toTrigonometric fcn.
Tunable: Yes
A length-N vector containing the phase offsets, in radians, of the sine waves in each of N output channels, or a scalar to be applied to all N channels. The vector length must be the same as that specified for the Amplitude and Frequency parameters.
Tip
This parameter is tunable (Simulink) when you set:
Solver Type to
Fixed-step.Sample mode to
Continuous.Sample mode to
Discreteand Computation method toTrigonometric fcn.
Tunable: Yes
Specify the sampling mode as Continuous or
Discrete:
ContinuousIn continuous mode, the sinusoid in the ith channel, yi, is computed as a continuous function,
and the block's output is continuous. In this mode, the block operates the same as the Simulink® Sine Wave block with Sample time set to
0. This mode offers high accuracy, but requires trigonometric function evaluations at each simulation step, which is computationally expensive. Also, because this method tracks absolute simulation time, a discontinuity will eventually occur when the time value reaches its maximum limit.Note also that many DSP System Toolbox™ blocks do not accept continuous-time inputs.
DiscreteIn discrete mode, the block can generate discrete-time output by directly evaluating the trigonometric function, by table lookup, or by a differential method. For more information on these computation methods, see Algorithms.
The type of waveform to generate: Real
specifies a real sine wave, Complex specifies
a complex exponential.
The method by which discrete-time sinusoids are generated:
Trigonometric fcn, Table
lookup, or Differential.
For more information on each of the available options, see Algorithms.
Dependencies
This parameter is only visible when you set the Sample
mode to Discrete.
Note
To generate fixed-point sinusoids, you must set the
Computation method to
Table lookup.
Optimize the table of sine values for one of these:
Speed–– The table contains a fixed number of elements. The block supports the frequency F and the sample rate Fs values such that F/Fs can be represented as a ratio of 16 bit integers. For example, if you set F as 1.35 Hz and Fs as 2.15 Hz, the ratio of F/Fs can be written as 27/43 which can be represented by 16-bit integers.Memory–– The table contains k/4 elements, where k = Fs/F. The period of each sinusoid must be an integer multiple of 4/Fs.
Dependencies
This parameter is only visible when you set the
Computation method parameter to
Table lookup.
The period with which the sine wave is sampled, Ts, as a finite scalar, greater than zero. The output frame period of the block is MTs, where you specify M in the Samples per frame parameter.
Dependencies
To enable this parameter, set Sample mode to
Discrete.
The number of consecutive samples from each sinusoid to buffer into the output frame, M, specified as a positive scalar integer. This parameter is not tunable.
The block output is an M-by-N matrix with frame period MTs, where you specify Ts in the Sample time parameter.
Dependencies
To enable this parameter, set Sample mode to
Discrete.
This parameter determines the behavior of the Sine Wave
block when an enabled subsystem is reenabled. The block can either reset
itself to its starting state (Restart at time
zero), or resume generating the sinusoid based on the
current simulation time (Catch up to simulation
time).
Dependencies
This parameter only applies when the Sine Wave
block is located inside an enabled subsystem and the
States when enabling parameter of the
Enable (Simulink) block is set
to reset.
Data Types
Select how you would like to specify the data type properties of the Output data type. You can choose:
Inherit— Lets you specify a rule for inheriting a data type, for example,Inherit: Inherit via back propagationBuilt in— Lets you specify a built in data type, for example,doubleFixed point— Lets you specify the fixed-point attributes of the data type.Expression— Lets you specify an expression that evaluates to a valid data type, for example,fixdt(1,16)
Data Type Assistant
Select how you would like to specify the data type properties of the Output data type. You can choose:
Inherit— Lets you specify a rule for inheriting a data type, for example,Inherit: Inherit via back propagationBuilt in— Lets you specify a built-in data type, for example,doubleFixed point— Lets you specify the fixed-point attributes of the data type.Expression— Lets you specify an expression that evaluates to a valid data type, for example,fixdt(1,16)
For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Specify the signedness of the fixed-point output. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Limitations
The Sine Wave only supports
Signed data types.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Dependencies
To enable this parameter, set Mode to
Fixed point
Specify the bit size of the word that holds the quantized integer as a positive integer from 2 to 128. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Dependencies
To enable this parameter, set Mode to
Fixed point
Specify the fraction length of the fixed-point data type as a positive or negative integer scalar.
Dependencies
To enable this parameter, set Mode to
Fixed point and
Scaling to Binary
point.
Select the data type override mode for this signal. You can select:
Inherit— Inherits the data type override setting specified for the model.Off— Ignores the data type override setting specified for the model and uses the fixed-point data type you specify.
Dependencies
To enable this parameter, set Mode to
Built in or Fixed
point. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Algorithms
When you select Discrete from the Sample
mode parameter, the secondary Computation method
parameter provides three options for generating the discrete sinusoid:
Trigonometric fcn, Table
lookup, and Differential.
The trigonometric function method computes the sinusoid in the ith channel, yi, by sampling the continuous function
with a period of Ts, where you specify
Ts in the Sample
time parameter. This mode of operation has the same benefits and
liabilities as the Continuous sample mode.
At each sample time, the block evaluates the sine function at the appropriate time value within the first cycle of the sinusoid. By constraining trigonometric evaluations to the first cycle of each sinusoid, the block avoids the imprecision of computing the sine of very large numbers, and eliminates the possibility of discontinuity during extended operations (when an absolute time variable might overflow). This method therefore avoids the memory demands of the table lookup method at the expense of many more floating-point operations.
The table lookup method precomputes unique samples of every output sinusoid at the start of simulation, and recalls the samples from memory as needed. A table of finite length can only be constructed when all output sequences repeat.
When you set the Optimize table for parameter to
Speed, the table constructed for each channel
contains a fixed number of elements. The algorithm supports frequency,
F, and the sample rate, Fs (1/sample time
Ts), values such that
F/Fs can be represented as a ratio of 16
bit integers. For example, if you set F as 1.35 Hz and
Fs as 2.15 Hz, the ratio of
F/Fs can be written as 27/43, which can be
represented by 16-bit integers.
When you set the Optimize table for parameter to
Memory, the table constructed for each channel
contains k/4 elements, where k =
Fs/F.
For long output sequences, the table lookup method requires far fewer floating-point operations than any of the other methods, but it can demand considerably more memory, especially for high sample rates (long tables). This method is recommended for models that are intended to emulate or generate code for DSP hardware and therefore must be optimized for execution speed.
Note
The lookup table for this block is constructed from double-precision
floating-point values. Thus, when you use the Table
lookup computation mode, the maximum amount of precision you
can achieve in your output is 53 bits. Setting the word length of the
Output or User-defined data type
to values greater than 53 bits does not improve the precision of your
output.
Tip
To generate fixed-point sinusoids, you must select Table
Lookup.
The differential method uses an incremental algorithm. This algorithm computes the output samples based on the output values computed at the previous sample time (and precomputed update terms) by using the following identities.
The update equations for the sinusoid in the ith channel, yi, can therefore be written in matrix form as
where you specify Ts in the Sample time parameter. Since Ts is constant, the right-hand matrix is a constant and can be computed once at the start of the simulation. The value of Aisin[2πfi(t+Ts)+ϕi] is then computed from the values of sin(2πfit+ϕi) and cos(2πfit+ϕi) by a simple matrix multiplication at each time step.
This mode offers reduced computational load, but is subject to drift over time due to cumulative quantization error. Because the method is not contingent on an absolute time value, there is no danger of discontinuity during extended operations (when an absolute time variable might overflow).
Extended Capabilities
The Sine Wave block references absolute simulation time when configured in continuous sample mode.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has one default HDL architecture.
| 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
|
| SynthesisAttributes |
Specifies the synthesis attributes for the blocks and block output signals in the model. The generated HDL code contains these attributes. For more information, see SynthesisAttributes (HDL Coder). |
The block supports these data types for HDL code generation:
| Output Port | Dimension | Fixed-Point | Floating-Point | Built-in Integers | Bus | Boolean | Complex Signal |
|---|---|---|---|---|---|---|---|
| Port_1 | Scalar Vector Matrix | Yes | Single Double | Yes | Yes | Yes | Yes |
When you use Output data
type as single or double
for the block, you can generate synthesizable HDL code by using native
floating-point technology. For more information, see Generate Target-Independent HDL Code with Native Floating-Point (HDL Coder). (since R2026a)
| Block Parameter | Limitations |
|---|---|
| Computation method | Computation method must be set
to |
| Sample mode | Sample mode must be set to
|
The block participates in these HDL optimizations to optimize the speed, and area.
Speed Optimization
| Optimization | Description |
|---|---|
| Specify Distributed Pipelining Settings (HDL Coder) | Distributed pipelining, or register retiming, is a speed optimization that moves existing delays in a design to reduce the critical path while preserving functional behavior. |
| Clock-Rate Pipelining (HDL Coder) | Clock-rate pipelining is an optimization framework in HDL Coder that allows other speed and area optimizations to introduce latency at the clock rate. |
| Delay Balancing (HDL Coder) | Using delay balancing, HDL Coder detects introduced latency along one path and then inserts matching delays on the other paths in your generated model. |
| Critical Path Estimation (HDL Coder) | To quickly identify the most likely critical path in your design, use Critical Path Estimation. Critical path estimation speeds up the iterative process of finding the critical path. To know blocks that are characterized in critical path estimation, see Characterized Blocks (HDL Coder). |
This block does not support frame-based vector output during HDL code generation. The vector outputs from amplitude and frequency array are supported.
Version History
Introduced before R2006aWhen you use Output data type as single or
double for the Sine Wave block, you can generate
synthesizable HDL code by using native floating-point technology. To generate the
HDL code with native floating-point, in the HDL Code Generation >
Floating-Point pane of the Configuration Parameters dialog box,
select the Use floating-point parameter. For more information
on native floating-point, see Generate Target-Independent HDL Code with Native Floating-Point (HDL Coder).
You can also use various HDL optimizations, such as distributed pipelining, hierarchy flattening, or balancing, for the block to generate optimized HDL code for your DSP application.
When you set Computation method to Table
lookup and Optimize table for to
Speed, the Sine Wave block supports
frequency, F, and the sample rate Fs, values
such that F/Fs can be represented as a ratio
of 16 bit integers. For example, if you set F as 1.35 Hz and
Fs as 2.15 Hz, the ratio of
F/Fs can be written as 27/43, which can be
represented by 16-bit integers.
When you set Computation method to Trigonometric
fcn, the Sine Wave block has been improved with
phase calculations for greater numerical accuracy and consistency. As a result, the
output values can differ from previous releases, especially for long signals.
See Also
Blocks
- Chirp | Signal From Workspace | Signal Generator (Simulink) | Sine Wave (Simulink) | Enabled Subsystem (Simulink)
Functions
Objects
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)