Engee documentation
Notebook

Wavelet transform of signals with scalogram construction

The wavelet transform is a powerful tool for analysing signals, which allows you to investigate time and frequency characteristics simultaneously. This method is particularly useful for processing non-linear and non-periodic signals such as biological data, financial series and acoustic signals. One of the most popular applications of wavelet analysis is the construction of scalograms, which are two-dimensional plots showing the distribution of signal energy over time and frequency.

For example, consider the task of analysing a composite signal consisting of two cosine components and random noise. We will declare the signal in Engee and perform the resulting analysis in MATLAB to compare the capabilities of these two environments.

In [ ]:
Pkg.add(["ContinuousWavelets", "Wavelets"])
In [ ]:
fs = 1000 # Частота дискретизации
t = 0:1/fs:1-1/fs # Вектор времени  
signal = cos.(2π*50*t) .+ cos.(2π*120*t) .+ randn(length(t))  # Композитный сигнал с шумом
plot(t, signal)
Out[0]:

To implement this analysis in Engee we need the following libraries:

  1. ContinuousWavelets
  2. Wavelets
  3. FFTW
In [ ]:
Pkg.add("Wavelets")
Pkg.add("ContinuousWavelets")
using ContinuousWavelets, Wavelets, FFTW

Let's analyse the code described below in detail.

wavelet is a function that creates a wavelet transducer object. In our case, it takes three arguments:

  1. Morlet(π) is a Morlet wave function with parameter π. The Morlet function is widely used in signal analysis due to its ability to effectively extract signal features at different scales.
  2. averagingType=NoAve() - defines the type of averaging. Here the absence of averaging is selected. This means that each point in the resulting array will correspond to the value of the wave coefficient without additional smoothing.
  3. β=2 - parameter determining the width of the Morlet function window. The higher the value of β, the narrower the window and the more accurate the signal localisation in the time domain, but the worse the resolution in the frequency domain.

cwt - this function performs continuous wave transformation (CWT) of the original signal using the created wave converter.

In [ ]:
c = wavelet(Morlet(π), averagingType=NoAve(), β=2)
res = cwt(signal, c)
heatmap(abs.(res)', xlabel= "time",ylabel="frequency")
Out[0]:

Now let's construct the same in MATLAB. In this case, cwt is different in syntax and calculates the wave transform coefficients for the input signal and number of scales. It is also important to clarify that a larger number of scales provides more detailed analysis, but requires more computational resources.

In [ ]:
using MATLAB
mat"""
cwt($(signal),200);
saveas(gcf, 'Wavelet.jpg'); % Сохраняет текущую фигуру как JPG
"""

load( "$(@__DIR__)/Wavelet.jpg" )
Out[0]:
No description has been provided for this image

Conclusion

The graphs showed that the results are identical in both environments.