Skip to main content
. 2025 Apr 30;13(5):1090. doi: 10.3390/biomedicines13051090
Algorithm 1. Annotating sleep apnea events based on QRS complex counts in ECG signals
Input
qrs_annotations (sample indices)
sampling_rate (samples per second)
time_window (duration of each window in seconds)
QRS_threshold (minimum QRSD count threshold to avoid labels)
Output:
apnea_annotations (list of labels: Apnea and normal lables)
Step:
1. window_size = time_window * sampling_rate
2. Determine num_windows = len(qrs_annotations)//window_size  3. Initialize an empty labels list called apnea_annotations = []
4. For each window i from 0 to num_window −1, do as follows:
   4.1 Set time start_sample = i * window_size
   4.2 Set end_sample = start_sample + window_size
   4.3 Count QRS in the current time window within start_sample, end_sample
   4.4 if QRS_count < QRS_threshold , then
    4.4.1 append apnea_annotations.append((‘A’, start_sample))
   Else
    4.4.2 apnea_annotations.append((‘N’, start_sample))