Signal convolution in Engee
Introduction
Convolution is one of the fundamental operations of digital signal processing. It describes the response of a linear stationary system to an arbitrary input impact and is widely used in filter analysis, communication channel modeling, image processing, and automatic control tasks.
Mathematically, the convolution operation for continuous signals is written as an integral:
and for discrete sequences as a sum:
The meaning of the operation is as follows: one of the sequences is mirrored, shifted relative to the other, multiplied element by element with it, and the results of the multiplication are summed up. The shift is repeated at each step until the sequences no longer overlap.
In this example, a numerical implementation of the convolution of two signals in the Julia environment is considered.:
-
Impulse response is a linearly decreasing function on the interval with;
-
Input signal - a rectangular pulse of a single amplitude in the interval with.
The purpose of the work is to demonstrate the step-by-step implementation of discrete convolution, correctly take into account the sampling step and visualize the original signals along with the result.
Initial data
Initialize the time domain, the impulse response, and the input signal function:
dt = 0.01 # time step
t1 = 0:dt:2
ft = 2 .- t1 # impulse response
t2 = -2:dt:2
gt = 3 .* ones(length(t2)) # The input signal
The convolution operation
Let's apply the convolution operation from the EngeeDSP library to the impulse response and the input signal:
yt = dt .* EngeeDSP.Functions.conv(ft, gt) # applying the convolution operation
ytx = dt .* (1:length(yt)) .+ first(t2)
The expected result is a trapezoidal output signal: a rise in the overlap area of the sequences, a flat top and a symmetrical decline. This form is natural: the convolution of a rectangular pulse with a linearly decreasing function gives a piecewise linear response.
Visualization
Let's plot the pulse response, input and output signals.:
# graphs of pulse response, input and output signals
p1 = plot(t1, ft, color=:red, linewidth=3, title="Impulse response", xlabel="", ylabel="The amplitude", grid=true, xlim=(-2, 2), legend=false)
p2 = plot(t2, gt, color=:green, linewidth=3, title="The input signal", xlabel="time, from", ylabel="The amplitude", grid=true, ylim=(0, 3.5), legend=false)
p3 = plot(ytx, yt, color=:blue, linewidth=3, title="Output signal", xlabel="time, from", ylabel="The amplitude", grid=true, legend=false)
plot(p1, p2, p3)
The discrete convolution operation has been performed.
Conclusion
In this example, a discrete convolution of two sequences is implemented. The output signal has a trapezoidal shape, which confirms the correctness of the algorithm and takes into account the sampling step. The example shows how a more complex system response is formed from simple signals. Convolution is widely used in practice: in digital filters, in signal transmission over communication channels, in radar, image and sound processing, in medical diagnostics, control systems, and in convolutional neural networks.
Engee has the EngeeDSP library for such tasks with ready-made functions for convolution, filtering, and spectral analysis. This allows you to focus on the logic of the algorithm without having to do the calculations manually. Using EngeeDSP.Functions.conv the script confirms this. This example can serve as a general illustration of convolution and a starting point for more complex signal processing tasks in Engee.