Engee documentation
Notebook

DSP task on the example of sigma-delta analogue-to-digital converter model

This example implements a Sigma-Delta analogue-to-digital converter (Sigma-Delta ADC) model, which is a type that uses the delta-sigma modulation method to achieve high accuracy and resolution in the measurement of analogue signals. It is widely used in various applications requiring high measurement accuracy such as: audio, measurement sensors, etc. (model sigma_delta_adc.engee):

sdadc.PNG

The following case study analyses the performance of Sigma-Delta ADC in Simulink and Engee and compares the results of the two development environments.

First of all it is necessary to connect the libraries:

In [ ]:
Pkg.add(["Statistics", "CSV"])
In [ ]:
# Подключение библиотек
using Plots
using CSV
using DataFrames
using Statistics
plotlyjs();

Running a model implemented in the Engee development environment.

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

results = engee.run( modelName )
Out[0]:
Dict{String, DataFrame} with 3 entries:
  "analog" => 51216×2 DataFrame…
  "SD_ADC" => 801×2 DataFrame…
  "diff"   => 51216×2 DataFrame

Visualisation of model outputs

In [ ]:
SD_ADC_res_t = results["SD_ADC"].time;
SD_ADC_res_d = results["SD_ADC"].value;
p_adc_da_sl = plot(SD_ADC_res_t, SD_ADC_res_d, legend = false) # Построение графика
plot!(title = "Результаты моделирования в Engee", ylabel = "Цифровой сигнал", xlabel="Время, c") # Подпись осей и заголовка графика
Out[0]:

Simulink modelling results:

In [ ]:
using MATLAB # Подключение ядра MATLAB
mat"cd $(@__DIR__)"
mat"""
    out = sim('sigma_delta_adc');
    sig = getElement(out.yout,1);
    $DA_times = sig.Values.Time;
    $DA_values = sig.Values.Data;
    """; # Запуск Simulink
>> [Warning: MATLAB has disabled some advanced graphics rendering features by
switching to software OpenGL. For more information, click <a
href="matlab:opengl('problems')">here</a>.] 
>> >> >> [Warning: The specified buffer for 'sigma_delta_adc/Transport Delay' was too
small. During simulation, the buffer size was temporarily increased to 3072. In
order to generate code, you need to update the buffer size parameter] 
In [ ]:
p_adc_da_sl = plot(DA_times, DA_values, legend = false) 
plot!(title = "Результаты моделирования в Simulink", ylabel = "Цифровой сигнал", xlabel="Время, c")
Out[0]:

The models use a variable step solver. It is necessary to "synchronise" the signals. First, let's superimpose the graphs on each other:

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

Find the intersection of the two vectors with the simulation time:

In [ ]:
DA_times = DA_times[1:length(SD_ADC_res_t)];
DA_values = DA_values[1:length(SD_ADC_res_d)];
isect_idx = findall(in(SD_ADC_res_t),DA_times);

Then, we need to get the values at the common points

In [ ]:
sd_comp_t = DA_times[isect_idx];
sd_comp_sl = DA_values[isect_idx];
sd_comp_en = SD_ADC_res_d[isect_idx];

Now we can correctly compare the results of Simulink and Engee:

In [ ]:
adc_abs_tol = sd_comp_sl - sd_comp_en;
mean_adc_tol = abs(mean(adc_abs_tol));
adc_rel_tol = (sd_comp_sl - sd_comp_en)./sd_comp_sl;
mean_adc_tol_rel = abs(mean(filter(!isnan,adc_rel_tol)));
println("Средняя абсолютная погрешность вычислений:", mean_adc_tol);
println("Средняя относительная погрешность вычислений, %:", abs(mean_adc_tol_rel*100)); 
Средняя абсолютная погрешность вычислений:3.643855761728174e-18
Средняя относительная погрешность вычислений, %:9.729906822505499e-15
In [ ]:
engee.close( modelName, force=true);

Conclusion

To summarise, this example has implemented a sigma-delta analogue-to-digital converter model. Several conclusions can be drawn from this example:

  1. Engee is as accurate as Simulink.
  2. Engee allows to use MOS, and due to a large library of blocks we have the opportunity to implement a large functionality of blocks.
  3. And also, if the functionality of Engee is not enough, we can use the functionality of MATLAB inside Engee.