Engee documentation
Notebook

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.

image.png

Next, we'll connect an auxiliary function to launch 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, 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.

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

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.

Blocks used in example