R/preprocessing.R
correct_rr_cubic_spline.RdApplies cubic spline interpolation to detect and correct artifacts in RR intervals. This method follows the Kubios methodology and balances automation with accuracy.
correct_rr_cubic_spline(
rr_intervals,
threshold_percent = 25,
hr_adaptive = TRUE,
max_correction_rate = 5
)Numeric vector of RR intervals in milliseconds
Percentage threshold for artifact detection. Default is 25% following Kubios methodology
Logical indicating whether to use HR-adaptive thresholds. Default is TRUE
Maximum percentage of beats that can be corrected. Default is 5% to avoid over-smoothing
A list containing:
corrected_rr: Numeric vector of corrected RR intervals
artifact_mask: Logical vector indicating which beats were corrected
n_corrected: Number of intervals that were corrected
This function implements the Kubios-style cubic spline correction:
Uses HR-adaptive thresholds (20-30% or 0.20-0.30s ranges)
Limits corrections to <5% of beats to avoid over-smoothing
Applies cubic spline interpolation using R's spline() function
Automatically detects artifacts based on percentage deviation
The method balances automated detection with preservation of physiological variability, making it widely adopted in HRV research.
Based on Kubios HRV methodology for cubic spline artifact correction.
if (FALSE) { # \dontrun{
rr_data <- c(800, 850, 400, 830, 810, 1600, 820)
result <- correct_rr_cubic_spline(rr_data, threshold_percent = 25)
corrected_data <- result$corrected_rr
} # }