## 2 Materials and Methods
R peaks were located using the findpeaks() function, with minimum peak distance and height determined by plotting the reconstructed signal. These values were applied to findpeaks() to identify the QRS peak position, time location, and isolated R peaks, which were then plotted (Figure 4). For the MIT BIH Arrhythmia dataset, with a sampling frequency of 360 Hz, the MODWT was computed down to 6 levels using the sym4 wavelet, providing the frequency bands shown in Table 2. Detail coefficients from levels 3, 4, 5, and 6 were retained, and the others were set to zero. The reconstructed signal was generated using IMODWT with the sym4 wavelet. The same R peak localization procedure as in the normal sinus dataset analysis was followed. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Level** & **Scale** & **Frequency Band (Hz)** \\ \hline
1 & 2 & 64–128 \\
2 & 4 & 32–64 \\
3 & 8 & 16–32 \\
4 & 16 & 8–16 \\
5 & 32 & 4–8 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Frequency ranges for each level in DWT (sampling frequency 128 Hz). Figure 4: ECG signal of normal sinus rhythm recording—16,265. The Y-axis represents the voltage amplitudes of the ECG signal and the x-axis represents the time duration of the ECG signal. Additionally, MODWPT, another wavelet decomposition method, was used to locate R peaks following the same steps as in the MODWT method. The final step was to calculate HRV using RR intervals. HRV analysis, a key objective of this study, involves calculating the variation between consecutive heartbeats, or the distance between R peaks (Figure 5). This was performed by using the following code:  
rr_intervals = diff(locs) \(\times\) 1000;  
The difference between R peak time locations was used to compute the RR intervals. These values, initially in the millisecond range, were multiplied by 1000 to convert them into milliseconds. The RR interval values were then plotted against the beat number (Figure 6), representing HRV. Next, the frequency components of the RR intervals were extracted using CWT for a time-frequency analysis. The sampling frequency and time vector of the RR intervals were calculated based on the number of RR intervals and the original ECG signal's sampling frequency:  
rr_intervals_Fs = (length(rr_intervals)/length(samples)) \(\times\) Fs;  
rr_intervals_t = (0:(length(rr_intervals) - 1))/(rr_intervals_Fs \(\times\) 60);  
The CWT spectrogram was then plotted using the cwt() function, as shown in Figure 7. \begin{table}
\begin{tabular}{c c c} \hline
**Level** & **Scale** & **Frequency Band (Hz)** \\ \hline
1 & 2 & 90–180 \\
2 & 4 & 45–90 \\
3 & 8 & 22.5–45 \\
4 & 16 & 11.25–22.5 \\
5 & 32 & 5.625–11.25 \\
6 & 64 & 2.8125–5.625 \\ \hline \end{tabular}
\end{table} 
Table 2: Frequency ranges for each level in DWT (sampling frequency 360 Hz). Figure 5: Reconstructed signal containing R peaks in red color annotations of record no. 16,265. In the HRV analysis, the time-localized frequency components can be extracted by applying inverse continuous wavelet transform (ICWT) to the ECG signal [35]. This was carried out by reconstructing the long-term ECG signal for each frequency band separately. ECG signal is divided into 4 major frequency bands: ultra-low frequency (LF), very low frequency (VLF), low frequency (LF), and high frequency (HF) (Figure 8). These frequency band values are different for short-term and long-term ECG signals. For short-term ECG signals, the frequency bands are defined as VLF \(\leq\) 0.04 Hz, LF range: 0.04-0.15 Hz, and HF range: 0.15-0.4 Hz. For long-term ECG signals, the frequency bands are defined as ULF \(\leq\) 0.003 Hz, VLF range: 0.003-0.04 Hz, LF range: 0.04-0.15 Hz, and HF range-0.15-0.4 Hz [36]. Figure 6: The graph of RR intervals vs. the beat number. This is the representation of variation in the heart rate, HRV. Figure 7: The CWT spectrogram of record no. 16,265. CWT spectrum represents 3 dimensions: frequency, time, and the RR interval magnitude by each coordinate. The dashed line is the cone of influence which indicates the more accurate results inside the cone.