# Sine Wave

Generate continuous or discrete sine wave

• Library:
• 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

$y=A\mathrm{sin}\left(2\pi ft+\varphi \right)$

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

$y=A{e}^{j\left(2\pi ft+\varphi \right)}=A\left\{\mathrm{cos}\left(2\pi ft+\varphi \right)+j\mathrm{sin}\left(2\pi ft+\varphi \right)\right\}$

### 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 = Real

• Amplitude = [1 2 3]

• Frequency = [1000 500 250]

• Phase offset = [0 0 pi/2]

## Ports

### Output

expand all

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

expand all

### 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 either:

• Sample mode to Continuous.

• Sample mode to Discrete and Computation method to Trigonometric 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 either:

• Sample mode to Continuous.

• Sample mode to Discrete and Computation method to Trigonometric fcn.

Tunable: Yes

Specify the sampling mode as Continuous or Discrete:

• Continuous

In continuous mode, the sinusoid in the ith channel, yi, is computed as a continuous function,

$\begin{array}{ll}{y}_{i}={A}_{i}\mathrm{sin}\left(2\pi {f}_{i}t+{\varphi }_{i}\right)\hfill & \text{(real)}\hfill \\ \begin{array}{l}\\ \text{or}\\ \end{array}\hfill & \hfill \\ {y}_{i}={A}_{i}{e}^{j\left(2\pi {f}_{i}t+{\varphi }_{i}\right)}\hfill & \text{(complex)}\hfill \end{array}$

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.

• Discrete

In 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.

Optimizes the table of sine values for Speed or Memory. When optimized for speed, the table contains k elements, and when optimized for memory, the table contains k/4 elements, where k is the number of input samples in one full period of the sine wave.

#### 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 propagation

• Built in— Lets you specify a built in data type, for example, double

• Fixed 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)

## Block Characteristics

 Data Types double | fixed point | integer | single Direct Feedthrough no Multidimensional Signals no Variable-Size Signals no Zero-Crossing Detection no

## Algorithms

expand all

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.

## Version History

Introduced before R2006a