Extracts the amplitude envelope from rectified EMG signals using various methods.
Usage
extract_envelope(
data,
sampling_rate,
method = "lowpass",
cutoff = 6,
window_ms = 50,
filter_order = 4,
zero_phase = TRUE
)Arguments
- data
Rectified EMG signal. Can be a numeric vector (single channel), a matrix (T x M, time x channels), or a list of matrices. Should typically be rectified before envelope extraction.
- sampling_rate
Sampling frequency in Hz.
- method
Envelope extraction method:
"lowpass": Low-pass filter (default, most common)"rms": Root Mean Square with sliding window"moving_average": Simple moving average
- cutoff
Cutoff frequency for low-pass filter in Hz. Only used when
method = "lowpass". Default is 6 Hz.- window_ms
Window size in milliseconds for RMS or moving average. Only used when
methodis"rms"or"moving_average". Default is 50 ms.- filter_order
Filter order for low-pass method. Default is 4.
- zero_phase
Logical. If TRUE (default), applies zero-phase filtering for the low-pass method.
Details
The envelope represents the amplitude modulation of the EMG signal, showing muscle activation patterns over time. Common approaches:
Low-pass filter: Applies a Butterworth low-pass filter to the rectified signal. Cutoff frequency typically 4-10 Hz.
RMS: Computes root mean square in a sliding window. Good for preserving amplitude information.
Moving average: Simple smoothing with a sliding window. Fast but may introduce artifacts at window edges.
Examples
if (FALSE) { # \dontrun{
# Generate and process EMG
fs <- 1000
raw_emg <- rnorm(1000)
rect_emg <- rectify(raw_emg)
# Low-pass envelope (most common)
env_lp <- extract_envelope(rect_emg, sampling_rate = fs, method = "lowpass")
# RMS envelope
env_rms <- extract_envelope(rect_emg, sampling_rate = fs,
method = "rms", window_ms = 100)
} # }