Zero crossing detection
Zero transition detection can be used to model piecewise functions in Engee.
This demo contains several blocks that generate zero transition events, including the Abs block. The simulation results can accurately depict when the input signal has changed from positive to negative, as shown below.
Next, we'll connect an auxiliary function to launch the model.
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
run_model("zc_detection") # Запуск модели.
sine = collect(simout["zc_detection/sine"]);
out = collect(simout["zc_detection/out"]);
clock = collect(simout["zc_detection/clock"]);
For clarity, we will build two graphs, the first graph will contain an input sinusoid relative to the time signal that controls the switching between the Saturate and Abs blocks, and the second will contain an output signal relative to the same time signal.
plot(clock.value, sine.value)
plot!(clock.value, out.value)
Conclusion
As we can see from the simulation results, the sine wave is first fed to the output from the Abs port, and after half the simulation time, the Saturate output is used.