Engee documentation
Notebook

Branching the solution algorithm

The presented example demonstrates the use of the Multiport Switch block to implement a mechanism for selecting one of several branches in the model. This block allows you to switch between different solutions depending on the set mode.

The system is organized as follows.

Selecting the operating mode.
The first input port of the Multiport Switch block is used to control the mode. This is a control signal that determines which branch of the solution needs to be activated.

Branch options:

  • The first branch forms a pure sine wave. This is a signal without adding any distortion or noise.
  • The second branch generates random noise, which can be used to simulate interference or random signals.
  • The third branch combines the signals from the first two. For this purpose, an adder unit is used, which summarizes the sinusoidal signal with noise, creating a noisy sinusoid.

As a result, either a sine wave or noise can be obtained at the output of the unit, or a combination of both, depending on the set mode.

This approach allows you to flexibly control the behavior of the model, which is useful for various scenarios. For example, in one mode it is possible to analyze a pure signal, in another — the effect of noise, and in the third — to study the properties of the signal under interference conditions. This makes the system convenient for modeling, testing, and analysis in conditions of changing parameters.

The model itself is shown in the picture below.:
image.png
Now let's move on to analyzing the model.

Auxiliary functions

In [ ]:
# Подключение вспомогательной функции запуска модели.
function run_model( name_model)
    
    Path = (@__DIR__) * "/" * name_model * ".engee"
    
    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end
    sleep(5)
    return model_output
end

gr()
Out[0]:
Plots.GRBackend()

Comparison of modes

In [ ]:
mode=1
run_model("Multiport_Switch") # Запуск модели.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Синусоида")
Building...
Progress 100%
Progress 100%
Out[0]:
In [ ]:
mode=2
run_model("Multiport_Switch") # Запуск модели.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Шум")
Building...
Progress 100%
Progress 100%
Out[0]:
In [ ]:
mode=3
run_model("Multiport_Switch") # Запуск модели.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Зашумленная синусоида")
Building...
Progress 100%
Progress 100%
Out[0]:

Conclusion

The graphs have confirmed the correct operation of the system: all modes are displayed as we expect them to be.

This model successfully demonstrates the possibility of choosing between a pure sine wave, noise and a noisy signal, providing a visual and flexible tool for analyzing various scenarios of working with signals.