Applies a comprehensive preprocessing pipeline to RR intervals, including physiological filtering and artifact detection. This is a convenience function that combines multiple preprocessing steps.

preprocess_rr_intervals(
  rr_intervals,
  min_rr = 272,
  max_rr = 2000,
  window_size = 7,
  threshold = 0.2,
  centered_window = FALSE
)

Arguments

rr_intervals

Numeric vector of RR intervals in milliseconds

min_rr

Minimum physiologically plausible RR interval in milliseconds. Default is 272 ms

max_rr

Maximum physiologically plausible RR interval in milliseconds. Default is 2000 ms

window_size

Size of the moving window for artifact detection. Default is 7 intervals

threshold

Threshold for artifact detection as a proportion. Default is 0.2

centered_window

Logical indicating whether the moving window should be centered. Default is FALSE

Value

A list containing:

  • cleaned_rr: Numeric vector of cleaned RR intervals (artifacts removed)

  • valid_mask: Logical vector indicating which original intervals are valid

  • n_removed_physiological: Number of intervals removed for physiological reasons

  • n_removed_artifacts: Number of intervals removed as artifacts

  • n_original: Original number of intervals

  • n_final: Final number of valid intervals

Details

The preprocessing pipeline applies the following steps in order:

  1. Physiological filtering using filter_physiological_rr()

  2. Artifact detection using detect_rr_artifacts()

  3. Combines both filters to create final valid mask

  4. Returns both cleaned data and diagnostic information

This function is designed to be the main entry point for RR interval preprocessing in the HRV analysis pipeline.

Examples

if (FALSE) { # \dontrun{
rr_data <- c(800, 850, 200, 900, 2500, 820, 890, 870)
result <- preprocess_rr_intervals(rr_data)
print(paste("Removed", result$n_removed_physiological + result$n_removed_artifacts,
            "of", result$n_original, "intervals"))
clean_data <- result$cleaned_rr
} # }