The Sine Wave block generates a sinusoidal signal. The unit can operate based on time or calculation steps.
If you select Use external signal for the Time parameter, you get a Sine Wave Function block.
Simulation Time Based Mode
The value of the output signal:
In time-based mode, the value of Sample time determines whether the unit operates in continuous or discrete mode.
0.0 (By default) - the unit operates in continuous mode.
>0.0 - the block operates in discrete mode.
Block behaviour in continuous mode
When operating in continuous mode, there may be losses of accuracy at large values of time.
Unit behaviour in discrete mode
A value of Sample time greater than zero causes the block to operate as if it were controlling a Zero-Order Hold block whose calculation step is set to this value.
In this way, it is possible to create models with sinusoidal signal sources that are discrete, rather than models that are hybrid continuous/discrete systems. Hybrid systems are inherently more complex and therefore take longer to model.
In discrete mode, this block uses a differential incremental algorithm instead of an absolute time based algorithm. As a result, the block can be useful in models designed to run for indefinite periods of time, such as vibration or fatigue testing.
The differential incremental algorithm calculates the sine based on the value calculated in the previous calculation step. This method uses the following trigonometric identities:
In matrix form:
Since is constant, the following expression is a constant:
Thus, the problem becomes one of matrix multiplication of the value of by a constant matrix to get .
The discrete mode reduces but does not eliminate the accumulation of rounding errors. This accumulation can occur because the computation of the block output at each time step depends on the value of the output at the previous step.
Methods for handling rounding errors in discrete mode
To handle rounding errors when the Sine Wave block is operating in discrete time-based mode, insert the Saturation block immediately after the Sine Wave block.
By inserting a saturation block at the output of the Sine Wave block, overshoot due to accumulation of rounding errors can be avoided.
Mode based on calculation steps
Calculation step mode uses the following formula to calculate the output signal value:
π
А - amplitude of the sinusoid.
- the number of calculation steps per period of the sinusoid.
- repeated integer value in the range from [0] to [p-1].
- phase shift of the signal.
- signal offset.
In this mode, is set to 0 at the first time step, and the block output is calculated using the formula described. In the next time step, is increased and the block output value is recalculated. When reaches , the block output is reset to 0. This process continues until the end of the simulation.
The step-based calculation method of calculating the block output is characterised by the fact that the value at a given time step is independent of the value at previous steps. Thus, this mode avoids accumulation of rounding errors.
Ports
Input
Port_1 - time scalar | vector | matrix
Input signal representing the time source in the calculation of the sinusoid.
Dependencies
To use this port, set the Time parameter to Use external signal.
Output
Port_1 - output signal scalar | vector | matrix
Output sinusoidal signal generated on the basis of block parameter values.
Data types:Float64.
Parameters
Sine type - sinusoid type Time based (by default) | Sample based
Specify the type of sinusoid that this block generates. Some parameters in the dialogue box appear depending on whether Time based or Sample based is selected.
Usage in program code
Block parameter
SineType
Value
Time based | Sample based
By default
Time basedTime based
Time (t) is the source of the time variable. Use simulation time (by default) | Use external signal
Specify whether to use simulation time or an external source as the value source for the time variable. If you specify Use external signal, the block creates an input port for the time source and works similarly to the Sine Wave Function block.