Documentation

Sine Wave

Generate sine wave, using simulation time as time source

  • Library:
  • Simulink / Sources

Description

The Sine Wave block outputs a sinusoidal waveform. The block can operate in time-based or sample-based mode.

不te

This block is the same as theSine Wave Functionblock that appears in the Math Operations library. If you selectUse external signal为了Timeparameter in the block dialog box, you get theSine Wave Functionblock.

Time-Based Mode

The block calculates the output waveform.

y = a m p l i t u d e × sin ( f r e q u e n c y × t i m e + p h a s e ) + b i a s

In time-based mode, the value of theSample timeparameter determines whether the block operates in continuous mode or discrete mode.

  • 0(默认值)导致块在连续模式下运行。

  • >0causes the block to operate in discrete mode.

For more information, seeSpecify Sample Time

连续模式的障碍行为

当operating in continuous mode, theSine Waveblock can become inaccurate due to loss of precision as time becomes very large.

Block Behavior in Discrete Mode

ASample timeparameter value greater than zero causes the block to behave as if it were driving aZero-Order Holdblock whose sample time is set to that value.

This way, you can build models with sine wave sources that are purely discrete, rather than models that are hybrid continuous/discrete systems. Hybrid systems are inherently more complex and as a result take more time to simulate.

In discrete mode, this block uses a differential incremental algorithm instead of one based on absolute time. As a result, the block can be useful in models intended to run for an indefinite length of time, such as in vibration or fatigue testing.

The differential incremental algorithm computes the sine based on the value computed at the previous sample time. This method uses the following trigonometric identities:

sin ( t + Δ t ) = sin ( t ) cos ( Δ t ) + sin ( Δ t ) cos ( t ) cos ( t + Δ t ) = cos ( t ) cos ( Δ t ) sin ( t ) sin ( Δ t )

In matrix form, these identities are:

[ sin ( t + Δ t ) cos ( t + Δ t ) ] = [ cos ( Δ t ) sin ( Δ t ) sin ( Δ t ) cos ( Δ t ) ] [ sin ( t ) cos ( t ) ]

Because Δtis constant, the following expression is a constant:

[ cos ( Δ t ) sin ( Δ t ) sin ( Δ t ) cos ( Δ t ) ]

Therefore, the problem becomes one of a matrix multiplication of the value of sin ( t ) by a constant matrix to obtain sin ( t + Δ t )

Discrete mode reduces but does not eliminate the accumulation of round-off errors, for example,(4*eps)。这种累积可能发生,因为在每个时间步骤中的块输出计算取决于上一个时间步骤的输出值。

在离散模式下处理圆形错误的方法

To handle round-off errors when the正弦波块operates in time-based discrete mode, use one of these methods.

Method Rationale

Insert aSaturationblock directly downstream of the Sine Wave block.

By setting saturation limits on the Sine Wave block output, you can remove overshoot due to accumulation of round-off errors.

Set up the Sine Wave block to use thesin()math library function to calculate block output.

  1. On the Sine Wave block dialog box, setTimetoUse external signalso that an input port appears on the block icon.

  2. Connect a clock signal to this input port using aDigital Clockblock.

  3. Set the sample time of the clock signal to the sample time of the Sine Wave block.

Thesin()math library function computes block output at each time step独立of output values from other time steps, preventing the accumulation of round-off errors.

Sample-Based Mode

Sample-based mode uses this formula to compute the output of theSine Waveblock.

y = A sin ( 2 π ( k + o ) / p ) + b

  • Ais the amplitude of the sine wave.

  • p是每个正弦波周期的时间样本的数量。

  • kis a repeating integer value that ranges from 0 top–1.

  • ois the offset (phase shift) of the signal.

  • bis the signal bias.

In this mode, Simulink®setskequal to0at the first time step and computes the block output, using the formula. At the next time step, Simulink incrementsk和验算的输出块。当kreachesp, Simulink resetskto0before computing the block output. This process continues until the end of the simulation.

基于样本的计算块在给定时间步骤输出的方法不取决于前一个时间步骤的输出。因此,此模式避免了圆形错误的积累。基于样本的模式支持提供它的子系统中的万博1manbetx重置语义。例如,如果Sine Waveblock is in a resettable subsystem that receives a reset trigger, the repeating integerkresets and the block output resets to its initial condition.

Ports

Output

expand all

Output sine wave signal created based on the block parameter values.

Data Types:double

Parameters

expand all

Specify the type of sine wave that this block generates. Some parameters in the dialog box appear depending on whether you select time-based or sample-based.

Programmatic Use

Block Parameter:SineType
Type: character vector
Values:'Time based'|'Sample based'
Default:'Time based'

Specify whether to use simulation time as the source of values for the time variable, or an external source. If you specify an external time source, the block creates an input port for the time source. When you select an external time source, the block is the same as theSine Wave Functionblock.

Programmatic Use

Block Parameter:TimeSource
Type: character vector
Values:'Use simulation time'|'Use external signal'
Default:'Use simulation time'

Specify the amplitude of the output sine wave signal.

Programmatic Use

Block Parameter:Amplitude
Type: character vector
Value: scalar
Default:'1'

指定在正弦中添加的常数值以产生输出。

Programmatic Use

Block Parameter:Bias
Type: character vector
Value: scalar
Default:'0'

指定的频率,在rad /秒。

Dependencies

To enable this parameter, setSine typetoTime based

Programmatic Use

Block Parameter:Frequence
Type: character vector
Value: scalar
Default:'1'

Specify the phase shift of the sine wave.

You cannot configure this parameter to appear in the generated code as a tunable global variable if you setTime (t)toUse simulation time。For example, if you setDefault parameter behaviortoTunableor apply a storage class to aSimulink.Parameterobject, thePhaseparameter does not appear in the generated code as a tunable global variable.

To generate code so that you can tune the phase during execution, setTime (t)toUse external signal。You can provide your own time input signal or use aDigital Clockblock to generate the time signal. For an example, seeTune Phase Parameter of Sine Wave Block During Code Execution(万博1manbetx仿真软件编码器).

Dependencies

To enable this parameter, setSine typetoTime based

Programmatic Use

Block Parameter:Phase
Type: character vector
Value: scalar
Default:'0'

Specify the number of samples per period.

Dependencies

To enable this parameter, setSine typetoSample based

Programmatic Use

Block Parameter:Samples
Type: character vector
Value: scalar
Default:'10'

在样本时间数中指定偏移(离散相移)。

Dependencies

To enable this parameter, setSine typetoSample based

Programmatic Use

Block Parameter:Offset
Type: character vector
Value: scalar
Default:'0'

Specify the sample period in seconds. The default is0。If the sine type is sample-based, the sample time must be greater than 0. SeeSpecify Sample Time

Programmatic Use

Block Parameter:SampleTime
Type: character vector
Value: scalar
Default:'0'

Specify the output dimensions to be a 1-D vector signal when other parameters are one-row and one-column matrices. If you do not select this box, the block outputs a signal of the same dimensionality as the numeric parameters. SeeDetermining the Output Dimensions of Source Blocksin the Simulink documentation. This parameter is not available when an external signal specifies time. In this case, if numeric parameters are column or row matrix values, the output is a 1-D vector.

Programmatic Use

Block Parameter:VectorParams1D
Type: character vector
Values:'off'|'on'
Default:'on'

Block Characteristics

Data Types

double

Multidimensional Signals

Variable-Size Signals

Extended Capabilities

Introduced before R2006a

Was this topic helpful?