Main Content

Sine Wave

Generate continuous or discrete sine wave

  • Sine Wave block

Libraries:
DSP System Toolbox / Sources
DSP System Toolbox HDL Support / Sources

Description

TheSine Waveblock 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 theOutput complexityparameter toReal. The real sinusoidal output is defined by an expression of the type

y = A sin ( 2 π f t + ϕ )

你指定Ain theAmplitudeparameter,fin hertz in theFrequencyparameter, andϕin radians in thePhase offsetparameter.

The block generates a complex exponential signal when you set theOutput complexityparameter toComplex. This complex exponential signal is defined by an expression of the type

y = A e j ( 2 π f t + ϕ ) = A { cos ( 2 π f t + ϕ ) + j sin ( 2 π f t + ϕ ) }

Generating Multichannel Outputs

For both real and complex sinusoids, theAmplitude,Frequency, andPhase offsetparameter values (A,f, andϕ) can be scalars or length-Nvectors, whereNis the desired number of channels in the output. When you specify at least one of these parameters as a length-Nvector, 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:

y = { sin ( 2000 π t ) (channel 1) 2 sin ( 1000 π t ) (channel 2) 3 sin ( 500 π t + π 2 ) (channel 3)

  • 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, seeDescription. For information about multichannel support, seeGenerating Multichannel Outputs.

Tip

To output fixed-point data types, you must setSample modetoDiscreteandComputation methodtoTable lookup.

Data Types:single|double|fixed point
Complex Number Support:Yes

Parameters

expand all

Main

A length-Nvector containing the amplitudes of the sine waves in each ofN输出通道,或a scalar to be applied to allNchannels. The vector length must be the same as that specified for theFrequencyandPhase offsetparameters.

Tip

This parameter istunable(Simulink)only when theComputation methodisTrigonometric fcnorDifferential.

Tunable:Yes

A length-Nvector containing frequencies, in hertz, of the sine waves in each ofN输出通道,或a scalar to be applied to allNchannels. The vector length must be the same as that specified for theAmplitudeandPhase offsetparameters. You can specify positive, zero, or negative frequencies.

Tip

This parameter istunable(Simulink)when you set either:

  • Sample modetoContinuous.

  • Sample modetoDiscreteandComputation methodtoTrigonometric fcn.

Tunable:Yes

A length-Nvector containing the phase offsets, in radians, of the sine waves in each ofN输出通道,或a scalar to be applied to allNchannels. The vector length must be the same as that specified for theAmplitudeandFrequencyparameters.

Tip

This parameter istunable(Simulink)when you set either:

  • Sample modetoContinuous.

  • Sample modetoDiscreteandComputation methodtoTrigonometric fcn.

Tunable:Yes

Specify the sampling mode asContinuousorDiscrete:

  • Continuous

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

    y i = A i sin ( 2 π f i t + ϕ i ) (real) or y i = A i e j ( 2 π f i t + ϕ i ) (complex)

    and the block's output is continuous. In this mode, the block operates the same as the Simulink®Sine Wave block withSample timeset to0. 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, seeAlgorithms.

The type of waveform to generate:Realspecifies a real sine wave,Complexspecifies a complex exponential.

The method by which discrete-time sinusoids are generated:Trigonometric fcn,Table lookup, orDifferential. For more information on each of the available options, seeAlgorithms.

Dependencies

This parameter is only visible when you set theSample modetoDiscrete.

Note

To generate fixed-point sinusoids, you must set theComputation methodtoTable lookup.

Optimizes the table of sine values forSpeedorMemory. When optimized for speed, the table containskelements, and when optimized for memory, the table containsk/4 elements, wherekis the number of input samples in one full period of the sine wave.

Dependencies

This parameter is only visible when you set theComputation methodparameter toTable 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 isMTs, where you specifyMin theSamples per frameparameter.

Dependencies

要启用该参数,设置Sample modetoDiscrete.

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 anM-by-Nmatrix with frame periodMTs, where you specifyTsin theSample timeparameter.

Dependencies

要启用该参数,设置Sample modetoDiscrete.

This parameter determines the behavior of theSine Waveblock 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 theSine Waveblock is located inside an enabled subsystem and theStates when enablingparameter of theEnable(Simulink)block is set toreset.

Data Types

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

  • Inherit— Lets you specify a rule for inheriting a data type, for example,通过反向传播继承:继承

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

  • 修复ed 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 theOutput data type. You can choose:

  • Inherit— Lets you specify a rule for inheriting a data type, for example,通过反向传播继承:继承

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

  • 修复ed 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, seeSpecify Data Types Using Data Type Assistant(Simulink).

Specify the signedness of the fixed-point output. For more information, seeSpecify Data Types Using Data Type Assistant(Simulink).

Limitations

TheSine Waveonly supportsSigneddata types.

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors. For more information, seeSpecify Data Types Using Data Type Assistant(Simulink).

Dependencies

要启用该参数,设置Modeto修复ed point

Specify the bit size of the word that holds the quantized integer as a positive integer from 2 to 128. For more information, seeSpecify Data Types Using Data Type Assistant(Simulink).

Dependencies

要启用该参数,设置Modeto修复ed point

Specify the fraction length of the fixed-point data type as a positive or negative integer scalar.

Dependencies

要启用该参数,设置Modeto修复ed pointandScalingtoBinary 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

要启用该参数,设置ModetoBuilt inor修复ed point. For more information, seeSpecify Data Types Using Data Type Assistant(Simulink).

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 selectDiscretefrom theSample modeparameter, the secondaryComputation methodparameter provides three options for generating the discrete sinusoid:Trigonometric fcn,Table lookup, andDifferential.

Extended Capabilities

Version History

Introduced before R2006a

See Also

Blocks

Functions

Objects