Engee documentation
Notebook

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.

In [ ]:
Pkg.add(["TickTock", "DSP"])
In [ ]:
using DSP
using TickTock
tick()
# Исходные сигналы
x = [1, 2, 3]
h = [0.2, 0.5, 0.75]

# Выполнение свертки
y = conv(x, h)
tock()
[ Info:  started timer at: 2024-12-10T07:19:13.139
[ Info:          0.004498645s: 4 milliseconds

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.

In [ ]:
using MATLAB
tick()
mat"""
% Исходные сигналы
x = [1, 2, 3];
h = [0.2, 0.5, 0.75];

% Выполнение свертки
y = conv(x, h);
"""
tock()
[ Info:  started timer at: 2024-12-10T07:19:13.204
[ Info:          0.185743239s: 185 milliseconds

As we can see, the execution speed in Engee is significantly higher than in MATLAB.

In [ ]:
println("Результат свертки в Engee:")
println(y)

mat"""
disp('Результат свертки в MATLAB:')
disp(y)
"""
Результат свертки в Engee:
[0.20000000000000018, 0.8999999999999997, 2.3499999999999996, 3.0, 2.2499999999999996]
>> >> >> Результат свертки в MATLAB:
>>     0.2000    0.9000    2.3500    3.0000    2.2500

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.