Engee documentation
Notebook

Diode bridge modelling

This example will demonstrate the solution to a classic electrical engineering problem - the conversion of AC voltage to DC voltage. This problem is solved with the help of rectifiers. One of the rectifier variants is the bridge circuit:

rect_scheme.png

Consider the corresponding circuit in Engee (model ssc_bridge_rectifier.engee):

image.png

The rectifier here is modelled using electrical component library blocks.

In [ ]:
Pkg.add(["Statistics", "CSV"])
In [ ]:
using Plots
using MATLAB
using CSV
using DataFrames
using Statistics

plotlyjs();

mat"start_simulink"
mat"p = genpath('/user/start/examples'); addpath(p);"

Realisation of the model run using software control:

Loading the model:

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

Running a loaded model:

In [ ]:
results = engee.run( modelName )
Out[0]:
Dict{String, DataFrame} with 2 entries:
  "AC Voltage" => 501×2 DataFrame…
  "DC Voltage" => 501×2 DataFrame

Load and visualise the data from the simulation.

Reading csv-files with voltage change data, with subsequent conversion into a matrix.

In [ ]:
Bridge_Engee_t = results["DC Voltage"].time;
Bridge_Engee_d = results["DC Voltage"].value;

Let's build a graph of rectified voltage:

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

The same circuit can be modelled in SimScape:

image.png

Run the model in Simulink and load the results into variables:

In [ ]:
mat"run_test_model('ssc_bridge_rectifier_demo');";
sl_rect_values = mat"SysOutput.Data";
sl_rect_times = mat"SysOutput.Time";

Let's look at the results of the simulation in SimScape:

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

Let's compare the graphs:

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

Conclusion:

This example demonstrated the modelling of a diode rectifier using command control of 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.