Engee documentation
Notebook

Discrete FIR filter

This example implements a sine wave filtering model and compares FIR filter operation in MATLAB and Engee. The Discrete FIR Filter block independently filters each channel of the input signal with a given digital FIR filter.

To realise the filtering we use standard settings of the Discrete FIR Filter block.

image.png Engee model

im.png Simulink model

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);"

Launch of the Engee model

Let's take a look at the results of the modelling in Engee:

In [ ]:
# Запуск модели
modelName = "FIR"
#engee.close( modelName, force=true ) # Для повторного запуска модели
PID_model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");

results = engee.run( PID_model )
Out[0]:
Dict{String, DataFrame} with 2 entries:
  "FIR_Out" => 101×2 DataFrame…
  "FIR_In"  => 101×2 DataFrame
In [ ]:
# Результаты моделирования
FIR_In_x = results["FIR_In"].time;
FIR_In_y = results["FIR_In"].value;
FIR_Out_x = results["FIR_Out"].time;
FIR_Out_y = results["FIR_Out"].value;
In [ ]:
# Построение графиков
plot(FIR_Out_x , FIR_Out_y, legend = false)
plot!(FIR_In_x , FIR_In_y, legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Данные", xlabel="Время, c")
Out[0]:

Let's compare the simulation results in Engee and Simulink. To do this, let's first run a simulation of the model.

In [ ]:
mat"run_test_model('FIR')";

Let's look at the results in Simulink:

In [ ]:
# Чтение выходов модели
x1 = mat"In.Data";
x2 = mat"Out.Data";
y = mat"Out.Time";
In [ ]:
# Построение графиков
plot(y, x2, legend = false)
plot!(y, x1, legend = false)  
plot!(title = "Результаты моделирования в Simulink", ylabel = "Отклик", xlabel="Время, c")
Out[0]:

Now plot the overlap between the output of Simulink and Engee.

In [ ]:
plot(y, x2, legend = false) # Simulink
plot!(FIR_Out_x , FIR_Out_y, legend = false) # Engee
Out[0]:

As we can see from the graphs above, the models work in the same way.

Conclusion

As a result of developing this example, we have implemented the FIR filter, as well as compared the capabilities of Engee with respect to modelling in Simulink and shown the connectivity of the MATLAB kernel to solve problems within the Engee development environment.