Mathematical convolution
Mathematical convolution is an operation that combines two functions to obtain a new function describing how one of them "blurs" or modifies the other. This operation is often used in signal analysis, image processing, control theory, and machine learning.
In this example, we will compare a simple call to this function in Engee and MATLAB.
Let's start with Engee. In this environment, conv is a function of the DSP (Digital Signal Processing) package that computes a discrete convolution of two arrays. In this example, the arrays x and h represent the original signals, the result of the convolution is stored in the variable y.
Pkg.add(["TickTock", "DSP"])
using DSP
using TickTock
tick()
# Исходные сигналы
x = [1, 2, 3]
h = [0.2, 0.5, 0.75]
# Выполнение свертки
y = conv(x, h)
tock()
Let's move on to the MATLAB function. conv in this case works exactly the same way and has no syntactic differences. Therefore, let's compare the speed of execution of these two scripts and the accuracy of execution.
using MATLAB
tick()
mat"""
% Исходные сигналы
x = [1, 2, 3];
h = [0.2, 0.5, 0.75];
% Выполнение свертки
y = conv(x, h);
"""
tock()
As we can see, the execution speed in Engee is significantly higher than in MATLAB.
println("Результат свертки в Engee:")
println(y)
mat"""
disp('Результат свертки в MATLAB:')
disp(y)
"""
When comparing the results, it can be seen that they are identical. The difference is that Engee does not round up the answers, and this allows you to get higher accuracy, rather than accumulating errors in the calculation process.
Conclusion
In this example, we performed a simple comparison of MATLAB and Engee and saw the advantages of a domestic development environment.