Differentiating link on operational amplifier¶
This example will demonstrate the modelling of a differentiating link by command control of the model in the Engee script editor, as well as running the model from the Simulink environment.
The model of the differentiating link on the operational amplifier is built with the help of libraries of electrical elements. The electrical elements are represented by a voltage source, a resistance, a capacitance, and an ideal operational amplifier.
Differentiator model (model ssc_differentiator_op_amp.engee) :
Realisation of the model run using software control:¶
Pkg.add(["Statistics", "CSV"])
using Plots
using MATLAB
using CSV
using DataFrames
using Statistics
gr();
mat"start_simulink"
mat"p = genpath('/user/start/examples'); addpath(p);"
Loading the model:
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");
Running a loaded model:
results = engee.run( modelName )
Load and visualise the data from the simulation.¶
Obtaining data on voltages taken from voltmeters:
DiffOpAmp_t = results["V1"].time;
DiffOpAmp_d1 = results["V1"].value;
DiffOpAmp_d2 = results["V2"].value;
Plotting a graph describing the change in voltage.
p_adc_da_e = plot(DiffOpAmp_t ,DiffOpAmp_d2 , legend = false)
plot!(DiffOpAmp_t ,DiffOpAmp_d1 , legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Напряжение, В", xlabel="Время, c")
The same circuit can be modelled in SimScape:
Run the model in Simulink and load the results into variables:
mat"run_test_model('ssc_opamp_differentiator_demo');";
sl_diff_opamp_values = mat"SysOutput.Data";
sl_diff_opamp_times = mat"SysOutput.Time";
Outputting simulation results in SimScape:
plot(sl_diff_opamp_times, sl_diff_opamp_values, legend = false)
plot!(title = "Результаты моделирования в Simulink", ylabel = "Напряжение", xlabel="Время, c")
Let's superimpose differentiated signals:
plot(DiffOpAmp_t ,DiffOpAmp_d1, label = "Engee")
plot!(title = "Сравнение результатов моделирования")
plot!(sl_diff_opamp_times, sl_diff_opamp_values, label = "Simulink")
plot!(legend = :outertopright,ylabel = "Цифровой сигнал", xlabel="Время, c")
Conclusion:¶
This example demonstrated the differentiating link simulation by command controlling the model in the Engee script editor as well as running the model from the Simulink environment. The calculations showed minimal difference in results when running the simulation in these two environments.