## 2 Materials and Methods  
ECG data for an HRV analysis were sourced from the trusted PhysioNet database [32], specifically the MIT-BIH Normal Sinus Rhythm and MIT-BIH Arrhythmia Databases. The Normal Sinus Rhythm Database includes 18 ECG recordings from patients referred to Beth Israel Deaconess Medical Center who have not exhibited significant arrhythmias, and involves 5 men aged from 26 to 45 and 13 women aged from 20 to 50. The recordings were sampled at a sampling rate of 128 Hz. The Arrhythmia Database consists of 24 h ambulatory ECG recordings of 47 patients, sampled at 360 Hz with 11-bit resolution [33]. The databases provide recordings in multiple formats (,atr,,dat,,hea, and.xws), which were challenging to handle. To ease processing, PhysioBank ATM offered ECG data in the more MATLAB-compatible.mat format. The process involved selecting the database and recording, setting the length to 1 h, and exporting both.mat and.info files. The.info file contains crucial data such as gain, base value, sampling frequency, and sampling time, which are needed for ECG waveform plotting. The analysis was performed using MATLAB 2021a, selecting 18 recordings from the Normal Sinus Rhythm and 46 from the Arrhythmia database. The MLII channel (lead II) ECG signal was chosen for the Arrhythmia dataset and the ECG1 signal for the Normal Sinus Rhythm dataset. Data from the.info files (sample rate, gain, and base values) were used in the analysis, with each step of the signal processing performed using self-written code (Figure 3). Figure 2: (**a**) Graphical representation of multi-resolution analysis. Wider wavelets (windows) are used in multi-resolution analysis to capture lower frequencies which provide high frequency resolution, and narrow wavelets (windows) are used to capture higher frequencies which provide high time resolution. (**b**) Multilevel decomposition. The approximation coefficients are shown by “A” and detailed coefficients are shown by “D”. At each level the number of coefficients is halved. The ECG signal data were loaded into MATLAB using the command ecg=load('16,265m.mat'), and the sampling rate, total number of samples, gain, and baseline were defined according to the.info file. Each ECG signal was normalized for consistency using the formula ecgsignal = ((ecg.val) \(-\) base)/gain. A time vector was created corresponding to each sample point, and the ECG signal was plotted against this vector, comparing it with the waveform from PhysioBank ATM. The next step involved locating the QRS complexes. Bandpass filtering was applied to identify R peaks within the QRS complexes, which contain middle frequencies in the ECG signal. There are many research studies conducted on detecting QRS complexes using wavelet transform. In those studies, the most common method of detecting QRS complex is using maximum overlap discrete wavelet transform (MODWT) or maximum overlap discrete wavelet packet transform (MODWPT) [22; 23; 24]. For this study, the maximal overlap discrete wavelet transform (MODWT) was used for wavelet decomposition. Different sampling frequencies in the Normal Sinus Rhythm and Arrhythmia datasets required different levels of decomposition. Previous studies have identified the QRS complex within the 0-50 Hz frequency range [34]. The MIT BIH normal sinus dataset, with a sampling frequency of 128 Hz, was analyzed using the MODWT, computed down to 5 levels with the db4 wavelet. The corresponding  
Figure 3: Methodology flowchart. This illustrates the multi-step process of HRV analysis. frequency bands are shown in Table 1. The detail coefficients from levels 2, 3, 4, and 5 were retained, while the others were set to zero using the following code:  
\[\text{wt}=\text{modwt(ecgsignal,5,'db4')};\]  
\[\text{wtrec}=\text{zeros(size(wt))};\]  
\[\text{wtrec(2:3:4:5,:)}=\text{wt(2:3:4:5,:)};\]  
Next, R peaks were isolated, and the inverse MODWT was applied to reconstruct the signal:  
\[\text{y}=\text{imodwt(wtrec,'db4')};\]  
To obtain positive peaks, the squared magnitude of the reconstructed signal was taken.