Branching of 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 switching between different solution options depending on the specified mode.
The system operation is organised as follows.
Mode selection. The first input port of the Multiport Switch block is used for mode control. This is a control signal that determines which branch of the solution should be activated.
Branch options:
- The first branch generates 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 model interference or random signals.
- The third branch combines the signals from the first two branches. This uses an adder block that sums the sine wave signal with the noise, creating a noisy sine wave.
As a result, the output of the block can be either a sine wave, noise, or a combination of both, depending on the specified mode.
This approach allows flexible control over the behaviour of the model, which is useful for different scenarios. For example, one mode can be used to analyse a clean signal, another mode to analyse the effect of noise, and a third mode to investigate the properties of the signal under interference conditions. This makes the system suitable for modelling, testing and analysis under changing parameters.
The model itself is shown in the figure below:
Now let's move on to analysing the model.
Auxiliary functions¶
# Подключение вспомогательной функции запуска модели.
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()
Mode comparison¶
mode=1
run_model("Multiport_Switch") # Запуск модели.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Синусоида")
mode=2
run_model("Multiport_Switch") # Запуск модели.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Шум")
mode=3
run_model("Multiport_Switch") # Запуск модели.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Зашумленная синусоида")
Conclusion¶
The constructed graphs confirmed the correctness of the system operation: all modes are displayed as we expect them to be.
This model successfully demonstrates the ability to choose between a pure sinusoid, noise and noisy signal, providing a clear and flexible tool for analysing different signal scenarios.