Engee documentation

Sine Wave

Sine wave signal generator.

blockType: Sin

Sine Wave

Path in the library:

/Basic/Sources/Sine Wave

Sine Wave Function

Path in the library:

/Basic/Math Operations/Sine Wave Function

Description

The Sine Wave block generates a sinusoidal signal. The block can operate based on time or based on calculation steps.

If the parameters Time (t) are set to . Use external signal, the block Sine Wave Function will be implemented.

Simulation time based mode

The value of the output signal:

.

In time-based mode, the value of the parameter 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 unit 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

If the value of the parameter Sample time is greater than zero, the block operates as if it were controlling the block Zero-Order Hold, the calculation step of which 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 block Sine Wave is operating in discrete time-based mode, insert block Saturation immediately after block Sine Wave. 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:

,

where

  • А - is the amplitude of the sinusoid;

  • - number of calculation steps per sinusoid period;

  • - a repeating integer value in the range from 0 to ;

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

Output

# OUT_1 — output signal
scalar | vector | matrix

Details

Output sinusoidal signal generated based on the parameters of the block.

Data types

Float64.

Complex numbers support

No

Input

# IN_1 — time
scalar | vector | matrix

Details

The input signal representing the time source in the calculation of a sinusoid.

Dependencies

To use this port, set the Time (t) parameters to . Use external signal.

Data types

Float64.

Complex numbers support

No

Parameters

Main

# Sine type — sinusoid type
Time based | Sample based

Details

Set the type of sine wave that this unit generates. Some parameters in the dialogue box appear depending on which type is selected: Time based or Sample based.

Values

Time based | Sample based

Default value

Time based

Program usage name

SineType

Tunable

No

Evaluatable

No

# Time (t) — time variable source
Use simulation time | Use external signal

Details

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 implements the block Sine Wave Function.

Values

Use simulation time | Use external signal

Default value

Program usage name

TimeSource

Tunable

No

Evaluatable

No

# Amplitude — sinusoidal amplitude
Scalar / array of real numbers

Details

The amplitude of the output sinusoidal signal.

Default value

1.0

Program usage name

Amplitude

Tunable

Yes

Evaluatable

Yes

# Bias — vertical displacement of the sinusoid
Scalar / array of real numbers

Details

A constant value added to the output value.

Default value

0.0

Program usage name

Bias

Tunable

Yes

Evaluatable

Yes

# Frequency (rad/sec) — sinusoidal frequency
Scalar / array of real numbers

Details

The frequency of the sinusoid in rad/s.

Dependencies

To use this parameter, set the Sine type parameters to . Time based.

Default value

1.0

Program usage name

Frequency

Tunable

Yes

Evaluatable

Yes

# Phase (rad) — sinusoidal phase shift
Scalar / array of real numbers

Details

The phase shift of a sinusoidal signal.

Dependencies

To use this parameter, set the Sine type parameters to Time based.

Default value

0.0

Program usage name

Phase

Tunable

Yes

Evaluatable

Yes

# Samples per period — number of steps per period
Scalar / array of real numbers

Details

Specify the number of calculation steps per period.

Dependencies

To use this parameter, set the Sine type parameters to . Sample based.

Default value

10

Program usage name

Samples

Tunable

Yes

Evaluatable

Yes

# Number of offset samples — offset in the number of calculation steps
Scalar / array of real numbers

Details

Set the offset (discrete phase shift) in the number of calculation steps.

Dependencies

To use this parameter, set the Sine type parameters to . Sample based.

Default value

0

Program usage name

Offset

Tunable

No

Evaluatable

Yes

# Sample time — interval between calculation steps
SampleTime (real number / vector of two real numbers)

Details

Specify the interval between calculation steps as a non-negative number. To inherit a calculation step, set this parameters to -1.

Dependencies

To use this parameter, set the parameter Time (t) to -1. Use simulation time.

Default value

0

Program usage name

SampleTime

Tunable

No

Evaluatable

Yes

Additional options

C code generation: Yes