# Online Algorithm for Deriving Heart Rate Variability Components and Their Time-Frequency Analysis
## 2 Materials and Methods  
### Data and Preprocessing  
The real data come from two different databases available on the PhysioNet platform [48]. The first one, from St. Vincent's University Hospital Sleep Disorders Clinic in Dublin, contains recordings from overnight polysomnographic study of 25 adults (age range: 28-68 years) with suspected sleep-disordered breathing. Subjects in the database were randomly selected from patients of the clinic over a half-year period. Additionally, the selected subjects had no known heart disease or autonomic dysfunction and were not taking medications that affect their heart rate. All polysomnographic signals, including ECG sampled at 128 Hz (modified lead V2), were recorded during one night of sleep using the Jaeger-Toennies system. Seven subjects were rejected (#5, 6, 8, 15, 21, 23, 26) due to frequent and long discontinuities in the ECG signal recordings. Because of the lack of ECG signal, it was also necessary to remove the first 54 min of Subject #13 and the last 2 min of Subject #19, resulting in a total of 18 ECG signals from the first database. The second Apnea-ECG Database was also based on sleep apnea-oriented polysomnographic studies. It contains 70 ECG signals lasted around 7-10 h recorded during sleep with a sampling rate of 100 Hz. This database was created from two sets of studies between 1993 and 1995 and 1998 and 1999 [49]. Of all the recordings, it was decided to use 18 ECGs of the best possible quality, especially without signal breaks or strong artifacts (#a04, a05, a09, a11, a18, a20, c09, c10, x01, x03, x05, x07, x08, x12, x16, x21, x23, x26). Even then, due to the lack of signal or its total distortion, it was necessary to remove the first 17 min of c09, 12 min of c10, 11 min of x01, 2 min of x03, 1 min of x26, and the last 10 min of x12. As a result, the recorded ECG signals cover natural, undisturbed by physical activity heartbeat and are long enough to allow the derivation of VLF and ULF components. Ultimately, data from 36 subjects, 18 from each database, were analyzed. The suggested optimal ECG sampling rate for the HRV spectral analysis is at least 250-500 Hz [22]. Therefore, each ECG signal was resampled from the original 128 or 100 Hz to 1000 Hz to find R peaks with a resolution of 1 ms. The exact location of the R peak was specified as the signal maximum near the QRS complex found using the PhysioToolkit software package (WFDB version 10.6.2) [48]. This software has ready-to-use algorithms and functions designed specifically for medical data processing and has been widely used by researchers since its public release, especially for the analysis of data from the PhysioNet database. However, these methods require parameter tuning, sometimes for each signal individually, and are prone to errors when the signal quality is poor. Then, the HRV signals were formed from the time intervals between consecutive R peaks. Finally, local modifications were made to the outliers by taking care not to modify the original phase of the signal (preserving the lower-frequency components of HRV) [39]: RRs lower than 0.61 s were added to the larger neighbor, and then, values greater than 1.22 s were split into two equal ones (related to the heart rate of 49-98 ppm when sleeping). Then, the timeline was reconstructed as a cumulative sum of RR intervals. It should be emphasized that the purpose of this work is to present quantitative information about HRV components; therefore, ECG signals should be of high-quality, without many artifacts or discontinuities, and sample modifications should be minimal and only local. In addition to 36 real signals, one synthetic HRV signal with features mimicking the real data was also used to assess the effectiveness of the decomposition algorithm by comparing the obtained results with the known parameters used to generate the synthetic waveform (ground truth). This non-stationary 6 h HRV was generated in the same way as in [39].