## 2 Materials and Methods
### Wavelet Transform
#### 2.1.1 Basic Principles and Steps of the Algorithm  
The wavelet decomposition algorithm is based on the use of a set of wavelet filters, including scaling (low-pass) and detail (high-pass) filters, which are associated with the selected wavelet. The decomposition process is iterative and is applied a given number of times, determined by the decomposition level ('level').  
Input data: The algorithm takes as input a one-dimensional signal ('signal'), a wavelet type ('wavelet') that specifies the set of filters to be used, and a decomposition depth ('level') indicating the number of decomposition levels.  
Initialization: At the beginning of the algorithm, an empty list of 'coeffs' is initialized to store the coefficients of the wavelet decomposition. The current signal being processed 'current signal' is set as equal to the input signal.  
Iterative decomposition process (FOR loop): The algorithm performs iterations, the number of which being determined by the level of decomposition ('level'). At each iteration \(k\) (from 1 to 'level'), the following steps are performed:  
* Scaling filter convolution: The current signal 'current signal' is subjected to a convolution operation with the scaling filter (low-pass filter) associated with the selected wavelet. The result of this operation is the approximating coefficients of the current level, denoted as \(cA_{k}\). These coefficients represent the low-frequency component of the signal, reflecting the overall structure or trend of the signal at a given resolution level.
* Wrap with detail filter: Simultaneously, the same current signal 'current signal' is convolved with a detail filter (high-pass filter) also originating from the selected wavelet. The result is the detailing coefficients of the current level, denoted as \(cD_{k}\). These coefficients represent the high-frequency component of the signal, containing details and abrupt changes such as noise and signal features.
* Downsampling (decimations): Both the approximating coefficients \(cA_{k}\) and the detailing coefficients \(cD_{k}\) undergo a \"downsampling\" operation, which consists of selecting every second sample. This is performed to reduce the size of the data and increase the level of resolution in the next decomposition step. Downsampling is a key part of the Mallat algorithm, ensuring its efficiency.
* Update current signal: For the next iteration of the algorithm, the current signal 'current signal' is replaced by the approximating coefficients \(cA_{k}\) of the current level. This means that, at the next level, only the approximated, smoother version of the previous level signal is decomposed.
* Saving detailing coefficients: The detailing coefficients \(cD_{k}\) obtained at the current level are temporarily stored in an internal buffer for later sequencing.  
Saving approximating coefficients of the last level: At the end of the iteration cycle, when a given decomposition depth ('level') has been reached, the last obtained approximating coefficients \(cA_{level}\) (which are the 'current signal' values at the last iteration) are stored in the 'coeffs' list. These coefficients represent the crudest approximation of the original signal.  
Add detail coefficients to the output array: Then, all the detailing coefficients \(cD_{k}\) stored in the internal buffer during the iterations are added to the 'coeffs' list. It is important to note that they are added in the order of the last level to the first, i.e., in the order \(cD_{level},cD_{level-1},\ldots,cD_{1}\).  
Output: The algorithm returns an array of coefficients 'coeffs', which is a list starting with the approximating coefficients of the last level \(cA_{level}\), followed by the detailing coefficients of all levels, from \(cD_{level}\) to \(cD_{1}\). Thus, the structure of the output coefficients is of the following form: \([cA_{level},cD_{level},cD_{level-1},\ldots,cD_{1}]\).