R/preprocessing.R
detect_artifacts_kubios.RdImplements research-validated artifact detection using Kubios-style time-varying thresholds with dRR series analysis. This method differentiates ectopic beats from normal sinus rhythm using adaptive thresholding.
detect_artifacts_kubios(
rr_intervals,
threshold_level = "medium",
hr_adaptive = TRUE
)A list containing:
artifact_indices: Integer vector of detected artifact positions
artifact_mask: Logical vector indicating artifacts
threshold_used: Numeric threshold value used for detection
drr_series: Difference RR series used for analysis
This function implements the Kubios-style artifact detection algorithm:
Calculates dRR (difference RR) series for adaptive analysis
Applies time-varying thresholds based on local HRV levels
Uses medium threshold (0.25s) as optimal for most populations
Differentiates ectopic beats from normal sinus rhythm
Adapts thresholds based on HR when hr_adaptive = TRUE
The method follows research recommendations from Kubios HRV 2023-2024 updates for automatic beat correction using research-validated thresholds.
Based on Kubios HRV methodology and research on time-varying thresholds for optimal RMSSD calculation accuracy across populations.
if (FALSE) { # \dontrun{
rr_data <- c(800, 850, 400, 1600, 820, 830) # Data with artifacts
result <- detect_artifacts_kubios(rr_data, threshold_level = "medium")
artifact_positions <- result$artifact_indices
} # }