Discrete FIR filter
This example implements a sinusoid filtering model and a comparison of FIR filter operation in MATLAB and Engee.
The Discrete FIR Filter unit independently filters each channel of the input signal with a preset digital FIR filter.
To implement filtering, we use the standard settings of the Discrete FIR Filter block.
The Engee model
The Simulink model
Pkg.add(["Statistics", "CSV"])
using Plots
using MATLAB
using CSV
using DataFrames
using Statistics
demoroot = @__DIR__
mat"start_simulink"
mat"p = genpath($demoroot); addpath(p);"
mat"p = genpath('/user/start/examples/helper_units'); addpath(p);"
Launching the Engee model
Let's look at the simulation results in Engee:
# Launching the model
modelName = "FIR"
PID_model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$demoroot/$(modelName).engee");
results = engee.run( PID_model )
# Simulation results
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;
# Plotting graphs
plot(FIR_Out_x , FIR_Out_y, legend = false)
plot!(FIR_In_x , FIR_In_y, legend = false)
plot!(title = "Simulation results in Engee", ylabel = "Data", xlabel="Time, c")
Launching the Simulink model
Let's compare the simulation results in Engee and Simulink. To do this, we will first run a simulation of the model.
mat"""run_test_model('FIR')""";
Let's look at the results in Simulink:
# Reading model outputs
x1 = mat"In.Data";
x2 = mat"Out.Data";
y = mat"Out.Time";
# Plotting graphs
plot(y, x2, legend = false)
plot!(y, x1, legend = false)
plot!(title = "Simulation results in Simulink", ylabel = "Response", xlabel="Time, c")
Now let's plot the overlap of the output data Simulink and Engee.
plot(y, x2, legend = false) # Simulink
plot!(FIR_Out_x , FIR_Out_y, legend = false) # Engee
As we can see from the graphs above, the models work the same way.
Conclusion
As a result of developing this example, we implemented a FIR filter, and also compared the capabilities of Engee regarding modeling in Simulink and showed the possibilities of connecting the MATLAB core to solve problems inside the Engee development environment.