Engee documentation
Notebook

The differentiating link on the operational amplifier

This example will demonstrate the modeling of the differentiating link using the command control of the model in the Engee script editor, as well as launching the model from the Simulink environment.

The model of the differentiating link on the operational amplifier is assembled using libraries of electrical elements. Electrical elements are represented by a voltage source, resistance, capacitance, as well as an ideal operational amplifier.

Model of the differentiating link (model ssc_differentiator_op_amp.engee) :

image.png

Implementation of the model launch using software control:

In [ ]:
Pkg.add(["Statistics", "CSV"])
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using MATLAB
using CSV
using DataFrames
using Statistics

demoroot = @__DIR__

mat"start_simulink"
mat"p = $demoroot; addpath(p);"
mat"p = '/user/start/examples/helper_units'; addpath(p);"

Loading the model:

In [ ]:
modelName = "ssc_differentiator_op_amp";
model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");

Launching the uploaded model:

In [ ]:
results = engee.run( modelName )
Out[0]:
SimulationResult(
    run_id => 9,
    "V2" => WorkspaceArray{Float64}("ssc_differentiator_op_amp/V2")
,
    "V1" => WorkspaceArray{Float64}("ssc_differentiator_op_amp/V1")

)

Loading and visualizing the data obtained during the simulation.

Obtaining data on the voltage taken from voltmeters:

In [ ]:
DiffOpAmp_t = results["V1"].time;
DiffOpAmp_d1 = results["V1"].value;
DiffOpAmp_d2 = results["V2"].value;

Plotting a graph describing the voltage change.

In [ ]:
p_adc_da_e = plot(DiffOpAmp_t ,DiffOpAmp_d1 , legend = false)
plot!(DiffOpAmp_t ,DiffOpAmp_d1 , legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Напряжение, В", xlabel="Время, c")
Out[0]:

The same scheme can be modeled in SimScape:

image.png

Running the model in Simulink and loading the results into variables:

In [ ]:
mat"run_test_model('ssc_opamp_differentiator_demo');";
sl_diff_opamp_values = mat"SysOutput.Data";
sl_diff_opamp_times = mat"SysOutput.Time";

Output of simulation results in SimScape:

In [ ]:
plot(sl_diff_opamp_times, sl_diff_opamp_values, legend = false) 
plot!(title = "Результаты моделирования в Simulink", ylabel = "Напряжение", xlabel="Время, c")
Out[0]:

Let's apply differentiated signals:

In [ ]:
plot(DiffOpAmp_t ,DiffOpAmp_d2, label = "Engee")
plot!(title = "Сравнение результатов моделирования")
plot!(sl_diff_opamp_times, sl_diff_opamp_values, label = "Simulink")
plot!(legend = :outertopright,ylabel = "Цифровой сигнал", xlabel="Время, c")
Out[0]:

Conclusion:

In this example, the model of the differentiating link was demonstrated using the command control of the model in the Engee script editor, as well as launching the model from the Simulink environment. The calculations showed a minimal difference in the results when running the simulation in these two environments.