Skip to contents

Applies a complete preprocessing pipeline to raw EMG data, transforming it into the format required for MFA/MPCA analysis.

Usage

preprocess_emg(
  raw_data,
  sampling_rate,
  pipeline_config = "default",
  mvc_data = NULL,
  channel_names = NULL,
  verbose = TRUE
)

Arguments

raw_data

Raw EMG data. Can be:

  • A matrix (T x M) for a single trial

  • A list of matrices for multiple trials/subjects

sampling_rate

Sampling frequency in Hz.

pipeline_config

Preprocessing configuration. Can be:

  • A character string: preset name ("default", "gait", "isometric", "fine_motor")

  • A list: custom configuration (see Details)

mvc_data

Optional MVC reference data for MVC normalization. Can be a matrix (T x M) or a list of matrices.

channel_names

Optional character vector of channel/muscle names.

verbose

Logical. If TRUE (default), prints progress information.

Value

An object of class "preprocessed_emg" containing:

  • data: Preprocessed data in list_of_data format (ready for MFA/MPCA)

  • processing_info: Record of all preprocessing steps and parameters

  • channel_names: Channel names

  • sampling_rate: Original sampling rate

Details

Processing Flow

The preprocessing pipeline transforms raw EMG signals into activation patterns suitable for muscle synergy analysis:


Raw EMG --> [DC Removal] --> [Bandpass] --> [Notch] --> [Rectify]
                |               |             |            |
           Remove bias    Extract signal  Remove power  Convert to
           and drift      bandwidth       line noise    positive
                                                            |
                                                            v
        Preprocessed <-- [Normalize] <-- [Envelope] <-------+
        (list_of_data)        |              |
                         Scale for      Extract amplitude
                         comparison     modulation

Processing Steps

1. DC Offset Removal

Removes electrode DC bias and signal drift. Methods: "mean" (subtract mean), "linear" (detrend), "polynomial". Typical use: Always recommended as first step.

2. Bandpass Filter

Extracts the EMG frequency band (typically 20-450 Hz). Removes low-frequency motion artifacts (<20 Hz) and high-frequency noise (>450 Hz). Parameters: low_cutoff=20, high_cutoff=450, order=4 (Butterworth).

3. Notch Filter

Removes power line interference (50 Hz in Japan/Europe, 60 Hz in Americas). Can also remove harmonics (100, 150, 200 Hz, etc.). Parameters: freq=50 or 60, Q=30, harmonics=TRUE.

4. Rectification

Converts bipolar EMG to unipolar by taking absolute value (full-wave) or setting negatives to zero (half-wave). Full-wave rectification is standard for envelope extraction.

5. Envelope Extraction

Extracts the amplitude envelope representing muscle activation pattern. Methods: "lowpass" (4-10 Hz cutoff), "rms" (root mean square), "moving_average". Lowpass with 6 Hz cutoff is most common.

6. Normalization

Scales signals for comparison across muscles/subjects/sessions. Methods: "mvc" (percentage of max voluntary contraction - gold standard), "max" (peak value), "zscore" (standardization), "range" (0-1 scaling).

Preset Configurations

default

General-purpose settings. Bandpass 20-450 Hz, 50 Hz notch, lowpass envelope (6 Hz), max normalization.

gait

Optimized for walking/gait analysis. Linear detrend, slower envelope (4 Hz cutoff), MVC normalization.

isometric

For sustained contractions. RMS envelope (100 ms window), MVC normalization. No time normalization needed.

fine_motor

For precise movements. Wider bandwidth (10-500 Hz), faster envelope (10 Hz cutoff).

Custom Configuration


config <- list(
  dc_removal = list(method = "mean"),
  bandpass = list(low = 20, high = 450, order = 4),
  notch = list(freq = 50, harmonics = TRUE),
  rectify = list(method = "full_wave"),
  envelope = list(method = "lowpass", cutoff = 6),
  normalize = list(method = "max")
)

Set any step to NULL or FALSE to skip it.

See also

emg_preset_config for preset configurations, bandpass_filter, notch_filter, rectify, extract_envelope, normalize_emg for individual processing functions.

Examples

if (FALSE) { # \dontrun{
# Basic usage with default settings
raw_emg <- matrix(rnorm(1000 * 8), ncol = 8)
processed <- preprocess_emg(raw_emg, sampling_rate = 1000)

# Use with MFA analysis
fit <- mfa_em_fit(processed$data, K = 2, r = 3)

# Custom configuration
config <- list(
  bandpass = list(low = 30, high = 400),
  notch = list(freq = 60),  # 60 Hz for Americas
  envelope = list(method = "rms", window_ms = 50),
  normalize = list(method = "mvc")
)
processed <- preprocess_emg(raw_emg, sampling_rate = 1000,
                            pipeline_config = config,
                            mvc_data = mvc_trials)
} # }