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.:

Now let's move on to analyzing the model.
Auxiliary functions
# Enabling the auxiliary model launch function.
function run_model( name_model)
Path = (@__DIR__) * "/" * name_model * ".engee"
if name_model in [m.name for m in engee.get_all_models()] # Checking the condition for loading a model into the kernel
model = engee.open( name_model ) # Open the model
model_output = engee.run( model, verbose=true ); # Launch the model
else
model = engee.load( Path, force=true ) # Upload a model
model_output = engee.run( model, verbose=true ); # Launch the model
engee.close( name_model, force=true ); # Close the model
end
sleep(5)
return model_output
end
gr()
Comparison of modes
mode=1
run_model("Multiport_Switch") # Launching the model.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "The sine wave")
mode=2
run_model("Multiport_Switch") # Launching the model.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Noise")
mode=3
run_model("Multiport_Switch") # Launching the model.
signal_out = collect(signal_out)
plot(signal_out.time,signal_out.value, title = "mode: $(mode)", label = "Noisy sine wave")
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.


