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()] # 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
run_model("zc_detection") # Launching the model.
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.