Engee documentation
Notebook

Zero crossing detection

Zero crossing detection can be used to model piecewise functions in Engee.

This demonstration contains several blocks that generate zero crossing events, including the Abs block. The simulation results can accurately depict when the input signal has changed from positive to negative, as shown below.

image.png

Next, let's connect an auxiliary function to run the model.

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
Out[0]:
run_model (generic function with 1 method)
In [ ]:
run_model("zc_detection") # Запуск модели.
Building...
Progress 100%
Out[0]:
Dict{String, DataFrames.DataFrame} with 3 entries:
  "sine"  => 1001×2 DataFrame…
  "out"   => 1001×2 DataFrame…
  "clock" => 1001×2 DataFrame
In [ ]:
sine = collect(simout["zc_detection/sine"]);
out = collect(simout["zc_detection/out"]);
clock = collect(simout["zc_detection/clock"]);

For clarity, let's build two graphs, the first graph will contain the input sinusoid relative to the time signal that controls the switching between Saturate and Abs blocks, and the second graph will contain the output signal relative to the same time signal.

In [ ]:
plot(clock.value, sine.value)
plot!(clock.value, out.value)
Out[0]:

Conclusion

As we can see from the simulation results, the sinusoid is first fed to the output from the Abs port, and after half of the simulation time the Saturate output is used.