Title: | Tools for Electromyogram Signals (EMG) Analysis |
---|---|
Description: | Data processing tools to compute the rectified, integrated and the averaged EMG. Routines for automatic detection of activation phases. A routine to compute and plot the ensemble average of the EMG. An EMG signal simulator for general purposes. |
Authors: | J.A. Guerrero, J.E. Macias-Diaz |
Maintainer: | Antonio Guerrero <[email protected]> |
License: | GPL (>= 3) |
Version: | 2.1.0 |
Built: | 2024-11-20 06:36:59 UTC |
Source: | CRAN |
Data processing tools to compute the rectified, integrated and the averaged EMG. Routines for automatic detection of activation phases. A routine to compute and plot the ensemble average of the EMG. An EMG signal simulator for general purposes.
Package: | biosignalEMG |
Type: | Package |
Version: | 2.1.0 |
Date: | 2018-02-18 |
License: | GPL (>= 3) |
Standard processing tools (rectification, integration, average, ensemble-average, onset/offset detection) of raw data of an EMG signal.
J.A. Guerrero, J.E. Macias-Diaz
Maintainer: J.A. Guerrero <[email protected]>
Konrad P. (2005) The ABC of EMG: A Practical Introduction to Kinesiological Electromyography. Version 1.0, Noraxon INC. USA
Winter D.A., Rau G., Kadefors R., Broman H., Deluca C.J. (1980) Units, Terms, and Sandards in the Reporting of EMG Research: A Report by the AdHoc Committee of the International Society of Electrophysiology and Kinesiology.
Guerrero J.A., Macias-Diaz J.E. (2014) A computational method for the detection of activation/deactivation patterns in biological signals with three levels of electric intensity. Math. Biosci. 248, 117–127.
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 2)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Full-wave rectified EMG emgr <- rectification(emgx, rtype = "fullwave") plot(emgr, main = "Rectified EMG") # Integration of the full-wave rectified EMG with reset points every # 200 samples emgi <- integration(emgr, reset = TRUE, reset.criteria = "samples", vreset = 200) plot(emgi, main = "Integrated EMG") # MA-envelope emgma <- envelope(emgx, method = "MA", wsize = 60) # Ensemble-averaged EMG ea <- eaemg(emgma, runs = emgx$on.off, what = 1, timenormalization = "mean", scalem = 1, empirical = TRUE, level = 0.9) plot(ea, lwd = 2, main = "Ensemble-averaged EMG") # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 2)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Full-wave rectified EMG emgr <- rectification(emgx, rtype = "fullwave") plot(emgr, main = "Rectified EMG") # Integration of the full-wave rectified EMG with reset points every # 200 samples emgi <- integration(emgr, reset = TRUE, reset.criteria = "samples", vreset = 200) plot(emgi, main = "Integrated EMG") # MA-envelope emgma <- envelope(emgx, method = "MA", wsize = 60) # Ensemble-averaged EMG ea <- eaemg(emgma, runs = emgx$on.off, what = 1, timenormalization = "mean", scalem = 1, empirical = TRUE, level = 0.9) plot(ea, lwd = 2, main = "Ensemble-averaged EMG") # reset graphical parameters par(op)
Functions to check if an object is an ‘emg’ object, or coerce it if possible.
as.emg(x, ...) ## Default S3 method: as.emg(x, ...) ## S3 method for class 'numeric' as.emg(x, ...) ## S3 method for class 'matrix' as.emg(x, ...) ## S3 method for class 'data.frame' as.emg(x, ...) is.emg(x)
as.emg(x, ...) ## Default S3 method: as.emg(x, ...) ## S3 method for class 'numeric' as.emg(x, ...) ## S3 method for class 'matrix' as.emg(x, ...) ## S3 method for class 'data.frame' as.emg(x, ...) is.emg(x)
x |
any R object. |
... |
additional arguments to be passed to methods (such as the samplingrate or the units of the EMG signal). |
as.emg
is a generic function with many methods to coerce an object to an ‘emg’ object.
is.emg
checks if x
is an ‘emg’ object.
as.emg
returns an ‘emg’ object.
is.emg
returns TRUE
if its argument is an ‘emg’ object (that is, has “emg” amongst its classes) and FALSE
otherwise.
J.A. Guerrero [email protected]
# Creates 1 sec. of a simulated EMG with only baseline noise x <- rnorm(1000) # Coerce a vector into an 'emg' object emgx <- as.emg(x, sampligrate = 1000) # Plot the data in emgx plot(emgx, main = "Synthetic EMG noise") # Load a data.frame with EMG data data(emg96627009) # Coerce a data.frame into an 'emg' object x <- as.emg(emg96627009) # Plot the data in x plot(x, main = "EMG of limb muscles of decorticated cat")
# Creates 1 sec. of a simulated EMG with only baseline noise x <- rnorm(1000) # Coerce a vector into an 'emg' object emgx <- as.emg(x, sampligrate = 1000) # Plot the data in emgx plot(emgx, main = "Synthetic EMG noise") # Load a data.frame with EMG data data(emg96627009) # Coerce a data.frame into an 'emg' object x <- as.emg(emg96627009) # Plot the data in x plot(x, main = "EMG of limb muscles of decorticated cat")
Adds a constant to all samples in the EMG to move the baseline noise mean in the presence of DC-offset or DC-bias.
dcbiasremoval(data, channel, baseline, data.name)
dcbiasremoval(data, channel, baseline, data.name)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
baseline |
constant to be substracted to the EMG signal. If not provided, this values is set so the resulting EMG has and overall mean of 0. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
An ‘emg’ object.
J.A. Guerrero [email protected]
See also emg
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Creates a random vector to simulate a baseline noise with a DC-offset x <- rnorm(1000, 1, 1) emg1 <- emg(x, samplingrate = 1000, units = "mV", data.name = "") plot(emg1, main = "Simulated EMG with a DC-offset") abline(h = mean(emg1$values), col = "red", lwd = 2) # Show the position of the overall mean # Remove the baseline noise mean emg2 <- dcbiasremoval(emg1) plot(emg2, main = "Simulated EMG with an overall zero mean") abline(h = mean(emg2$values), col = "red", lwd = 2) # Show the position of the overall mean # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Creates a random vector to simulate a baseline noise with a DC-offset x <- rnorm(1000, 1, 1) emg1 <- emg(x, samplingrate = 1000, units = "mV", data.name = "") plot(emg1, main = "Simulated EMG with a DC-offset") abline(h = mean(emg1$values), col = "red", lwd = 2) # Show the position of the overall mean # Remove the baseline noise mean emg2 <- dcbiasremoval(emg1) plot(emg2, main = "Simulated EMG with an overall zero mean") abline(h = mean(emg2$values), col = "red", lwd = 2) # Show the position of the overall mean # reset graphical parameters par(op)
Creates an ensemble-averaged EMG associated with a cyclical activity.
eaemg(data, channel, runs, what, timenormalization = c("min", "mean", "median", "max"), scalem = 1, empirical = TRUE, level = 0.9) ## S3 method for class 'eaemg' plot(x, ci.lty ="dashed", ...) ## S3 method for class 'eaemg' print(x, ...) ## S3 method for class 'eaemg' summary(object, ...)
eaemg(data, channel, runs, what, timenormalization = c("min", "mean", "median", "max"), scalem = 1, empirical = TRUE, level = 0.9) ## S3 method for class 'eaemg' plot(x, ci.lty ="dashed", ...) ## S3 method for class 'eaemg' print(x, ...) ## S3 method for class 'eaemg' summary(object, ...)
data |
an ‘emg’ object, usually rectified, moving-average of a rectified EMG or the computed envelope of an EMG. |
channel |
in case of multi-channel data, |
runs |
an ‘rle’ object indicating the lengths of succesive phases (active and inactive) or an atomic vector indicating in each position if the signal corresponds to a silence phase (0) or an active phase (1 or a greater integer). |
what |
which phases are going to be ensemble-averaged, active phases (1) or silence phases (0). |
timenormalization |
a string that indicates with respect to which value all phase durations should be normalized. It can be the “min” (default), “mean”, “median” or “max” duration of the phases. |
scalem |
a value (>=1) that controls the local detail of the ensemble. |
empirical |
logical; if |
level |
a value in |
x , object
|
an ‘eaemg’ object. |
ci.lty |
line type to plot the confidence intervals. |
... |
additional arguments to be passed to the generic function. |
Ensemble-Averaged EMG is usually applied to EMG signals associated with cyclical activities. In Ensemble-Averaged EMG the time base for each cycle is normalized and all the profiles are averaged. To successfully obtain the average profile, the data should be a rectified EMG, the moving average of a rectified EMG or the envelope of an EMG signal.
The runs
argument can be computed througth the rle
function of a thresholded envelope (see Examples) or computed with an onset/offset detection algorithm (see onoff_singlethres
and onoff_bonato
).
returns an object of class ‘eaemg’ which is a list with components:
intervals |
a matrix with three columns, each corresponding to the lower limit of the interval, the ensemble average and the upper limit of the interval. |
empirical |
the |
level |
the |
J.A. Guerrero [email protected]
Kumar S., Mital A. (1996) Electromyography In Ergonomics Taylor & Francis.
Esquivel M.E., Guerrero J.A., Macias-Diaz J.E. (2010) Activity pattern detection in electroneurographic and electromyogram signals through a heteroscedastic change-point method. Mathematical Biosciences 224(2) 109–117
rectification
, movingaverage
, envelope
, onoff_singlethres
, onoff_bonato
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Simulate 10 seconds of an EMG emgx <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") # MA-envelope emgma <- envelope(emgx, method = "MA", wsize = 60) # Ensemble-averaged EMG ea1 <- eaemg(emgma, runs = rle(emgx$on.off), what = 1, timenormalization = "max", scalem = 1, empirical = TRUE, level = 0.9) plot(ea1, lwd = 2, main = "Ensemble-averaged EMG using apriori onset/offset") # Determine the onset/offset runs using a thresholded envelope empiricalonoff <- onoff_singlethres(emgx, t = 0.05) ea2 <- eaemg(emgma, runs = empiricalonoff, what = 1, timenormalization = "max", scalem = 1, empirical = TRUE, level = 0.9) plot(ea2, lwd = 2, main = "Ensemble-averaged EMG using empirical onset/offset") # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Simulate 10 seconds of an EMG emgx <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") # MA-envelope emgma <- envelope(emgx, method = "MA", wsize = 60) # Ensemble-averaged EMG ea1 <- eaemg(emgma, runs = rle(emgx$on.off), what = 1, timenormalization = "max", scalem = 1, empirical = TRUE, level = 0.9) plot(ea1, lwd = 2, main = "Ensemble-averaged EMG using apriori onset/offset") # Determine the onset/offset runs using a thresholded envelope empiricalonoff <- onoff_singlethres(emgx, t = 0.05) ea2 <- eaemg(emgma, runs = empiricalonoff, what = 1, timenormalization = "max", scalem = 1, empirical = TRUE, level = 0.9) plot(ea2, lwd = 2, main = "Ensemble-averaged EMG using empirical onset/offset") # reset graphical parameters par(op)
Creates an ‘emg’ object to store an EMG signal.
emg(data, samplingrate = 0, units = "", data.name = "") ## S3 method for class 'emg' plot(x, channels = "all", samples = 0, type = "l", timeunits = c("samples", "seconds"), add = FALSE, ...) ## S3 method for class 'emg' print(x, ...) ## S3 method for class 'emg' summary(object, ...)
emg(data, samplingrate = 0, units = "", data.name = "") ## S3 method for class 'emg' plot(x, channels = "all", samples = 0, type = "l", timeunits = c("samples", "seconds"), add = FALSE, ...) ## S3 method for class 'emg' print(x, ...) ## S3 method for class 'emg' summary(object, ...)
data |
a vector or a matrix (one column per channel) containing the observed data. |
samplingrate |
number of samples carried per second, measured in Hertz. A value of 0 indicates that this value is missing or unknown. |
units |
a character vector specifying the units (usually ‘mV’) of the EMG data. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
x , object
|
an object of class ‘emg’. |
type |
what type of plot should be drawn. See |
channels |
channels to be considered by the procedure. Possible values: "all" to consider all channels in |
samples |
samples to be plotted. Possible values: 0 (all samples), an integer ‘n’ (to plot the first ‘n’ samples) and a vectors of 2 integers ‘n1’ and ‘n2’ (to plot samples from ‘n1’ to ‘n2’). |
timeunits |
a character vector specifying the units (samples or seconds) for the time axis. |
add |
logical; if |
... |
additional arguments to be passed to the generic function. |
returns an object of class ‘emg’ which is a list with components:
values |
a copy of |
units |
the |
samplingrate |
the |
data.name |
the |
J.A. Guerrero [email protected]
Konrad P. (2005) The ABC of EMG: A Practical Introduction to Kinesiological Electromyography. Version 1.0, Noraxon INC. USA.
Winter D.A., Rau G., Kadefors R., Broman H., Deluca C.J. (1980) Units, Terms, and Sandards in the Reporting of EMG Research: A Report by the AdHoc Committee of the International Society of Electrophysiology and Kinesiology.
# Creates a random vector to simulate an EMG signal x <- rnorm(10000, 0, 1) # Creates an 'emg' object to store x emg1 <- emg(x, samplingrate=1000, units="mV", data.name="") # Summarize and visualize the data summary(emg1) plot(emg1, main="Simulated EMG")
# Creates a random vector to simulate an EMG signal x <- rnorm(10000, 0, 1) # Creates an 'emg' object to store x emg1 <- emg(x, samplingrate=1000, units="mV", data.name="") # Summarize and visualize the data summary(emg1) plot(emg1, main="Simulated EMG")
Activity profile of spinal motoneurons recorded during fictive motion (scratching) evoked in an immobilized decorticate cat.
data("emg95306000")
data("emg95306000")
A data frame with 1999 observations on the following variable.
emg95306000
a numeric vector of EMG data
The sampling rate of the recorded data was 1000Hz. The data is in "mV".
Esquivel M.E., Guerrero J.A., Macias-Diaz J.E. (2010) Activity pattern detection in electroneurographic and electromyogram signals through a heteroscedastic change-point method. Mathematical Biosciences 224(2), 109–117
# Load data data(emg95306000) # Coerce data into an 'emg' object x <- as.emg(emg95306000, samplingrate=1000, units="mV") plot(x, main = "EMG of limb muscles of decorticated cat")
# Load data data(emg95306000) # Coerce data into an 'emg' object x <- as.emg(emg95306000, samplingrate=1000, units="mV") plot(x, main = "EMG of limb muscles of decorticated cat")
Activity profiles of spinal motoneurons recorded during fictive motion (scratching) evoked in an immobilized decorticate cat.
data("emg96627009")
data("emg96627009")
A data frame with 31979 observations on the following 4 variables.
a numeric vector of EMG data of the posterior bicep
a numeric vector of EMG data of the medial gastrocnemius
a numeric vector of EMG data of the flexor digitorum longus
MOTON.
a numeric vector of ENG data of a spinal motoneuron
This object contains the data in the file ‘emg96627009.DAT’ (provided within the package) which was recorded using AxoTape(TM). The sampling rate of the recorded data was 2500Hz. The data is in "mV" for all the 4 channels.
Esquivel M.E., Guerrero J.A., Macias-Diaz J.E. (2010) Activity pattern detection in electroneurographic and electromyogram signals through a heteroscedastic change-point method. Mathematical Biosciences 224(2), 109–117
# Load data data(emg96627009) # Coerce data into an 'emg' object x <- as.emg(emg96627009, samplingrate=2500, units="mV") summary(x)
# Load data data(emg96627009) # Coerce data into an 'emg' object x <- as.emg(emg96627009, samplingrate=2500, units="mV") summary(x)
Computes the RMS-envelope, the MA-envelope ot the LE-envelope of an EMG signal.
envelope(data, channel, method = c("MA","RMS","LE"), wsize, cutoff, n = 2, data.name, ...)
envelope(data, channel, method = c("MA","RMS","LE"), wsize, cutoff, n = 2, data.name, ...)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
method |
a string, "MA" (default) for MA-envelope, "RMS" for the RMS-envelope and "LE" for the LE-envelope. |
wsize |
determines the length of the moving window that is used to calculate the local averages of the data in RMS and MA envelopes. |
cutoff |
cutoff frequency in Hertz for the lowpass filter used in LE-envelope. |
n |
filter order for the lowpass filter used in LE-envelope. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
... |
Optional parameters for a MA-envelope: |
The MA-envelope corresponds to the moving average of the rectified EMG.
The RMS-envelope corresponds to the moving average of
where is each value of the EMG signal and
is the overall mean of the EMG signal.
LE-envelope or linear envelope is lowpass filtered rectified signal.
An ‘emg’ object containing the envelope of the EMG.
J.A. Guerrero [email protected]
Konrad P. (2005) The ABC of EMG: A Practical Introduction to Kinesiological Electromyography. Version 1.0, Noraxon INC. USA.
# Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") # MA-envelope emgma <- envelope(emgx, method = "MA", wsize = 60) # Superimpose the envelope on the EMG plot(emgx, main = "MA-envelope") plot(emgma, add = TRUE, lwd = 4, col = "red") # RMS-envelope emgrms <- envelope(emgx, method = "RMS", wsize = 60) # Superimpose the envelope on the EMG plot(emgx, main = "RMS-envelope") plot(emgrms, add = TRUE, lwd = 4, col = "red") # RMS-envelope emgle <- envelope(emgx, method = "LE", cutoff = 10) #10Hz # Superimpose the envelope on the EMG plot(emgx, main = "LE-envelope") plot(emgle, add = TRUE, lwd = 4, col = "red")
# Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") # MA-envelope emgma <- envelope(emgx, method = "MA", wsize = 60) # Superimpose the envelope on the EMG plot(emgx, main = "MA-envelope") plot(emgma, add = TRUE, lwd = 4, col = "red") # RMS-envelope emgrms <- envelope(emgx, method = "RMS", wsize = 60) # Superimpose the envelope on the EMG plot(emgx, main = "RMS-envelope") plot(emgrms, add = TRUE, lwd = 4, col = "red") # RMS-envelope emgle <- envelope(emgx, method = "LE", cutoff = 10) #10Hz # Superimpose the envelope on the EMG plot(emgx, main = "LE-envelope") plot(emgle, add = TRUE, lwd = 4, col = "red")
Extracts a specific channel from a multichannel ‘emg’ object.
extractchannel(data, channel, data.name)
extractchannel(data, channel, data.name)
data |
an ‘emg’ object. |
channel |
the specific channel to be extracted. Possible values: a character vector specifying the name of the channel to be considered (case sensitive) or a numeric value specifying the channel to be considered (number of column in |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
if channel
is a single channel ‘emg’ object, that single channel is returned as the output.
an ‘emg’ object containing a single channel.
J.A. Guerrero [email protected]
# Load a data.frame with EMG data data(emg96627009) # Coerce a data.frame into an 'emg' object x <- as.emg(emg96627009) # Extract the second channel in x y <- extractchannel(x, 2) # Plot the data in y plot(y, main = "Second channel of emg96627009") # Extract the channel 'ENG-FDL' in x (third channel) z <- extractchannel(x, "ENG-FDL") # Plot the data in z plot(z, main = "Third channel of emg96627009")
# Load a data.frame with EMG data data(emg96627009) # Coerce a data.frame into an 'emg' object x <- as.emg(emg96627009) # Extract the second channel in x y <- extractchannel(x, 2) # Plot the data in y plot(y, main = "Second channel of emg96627009") # Extract the channel 'ENG-FDL' in x (third channel) z <- extractchannel(x, "ENG-FDL") # Plot the data in z plot(z, main = "Third channel of emg96627009")
Highpass filter an EMG signal to remove signal artifacts and baseline noise contamination.
highpass(data, channel, cutoff = 50, n = 5, data.name)
highpass(data, channel, cutoff = 50, n = 5, data.name)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
cutoff |
cutoff frequency in Hertz for the highpass filter. See ‘Details’ for recommended values. |
n |
filter order for the highpass filter. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
This procedure performs a highpass filtering to the EMG signal in order to remove signal artifacts and baseline noise contamination (such as the DC-bias).
There are various recommendations for the value of the cutoff frequency, for example 5Hz (Merletti, 1999) and 10-20Hz (Freriks et.al., 1999).
An ‘emg’ object which contains the filtered EMG.
This procedure only uses a butterworth type filter of order n
. In order to apply a different type of filter, please see the documentation of the ‘signal’ package.
J.A. Guerrero [email protected]
Merletti R. (1999) Standards for Reporting EMG data. Journal of Electromyography and Kinesiology 9(1), III-IV http://www.isek-online.org/standards_emg.html
Freriks B., Stegeman D.F. and Hermens H.J. (1999) European Recommendations Standards for Surface Electromyography for Surface Electromyography, results of the SENIAM project. ISBN: 90-75452-14-4.
dcbiasremoval
, whitening
, lowpass
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Filter the fourth channel in x y <- highpass(x, cutoff = 100) # change graphical parameters to show multiple plots op <- par(mfcol = c(2, 2)) # Compute the rectified signals to see the effect of the filter x_rect <- rectification(x) y_rect <- rectification(y) # plot the original channel, the filtered channel and the corresponding # rectified signals plot(x, channel = 1, main = "Original channel") plot(y, main = "Highpass filtered channel") plot(x_rect, main = "Rectified channel") plot(y_rect, main = "Rectified highpass filtered channel") # reset graphical parameters par(op)
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Filter the fourth channel in x y <- highpass(x, cutoff = 100) # change graphical parameters to show multiple plots op <- par(mfcol = c(2, 2)) # Compute the rectified signals to see the effect of the filter x_rect <- rectification(x) y_rect <- rectification(y) # plot the original channel, the filtered channel and the corresponding # rectified signals plot(x, channel = 1, main = "Original channel") plot(y, main = "Highpass filtered channel") plot(x_rect, main = "Rectified channel") plot(y_rect, main = "Rectified highpass filtered channel") # reset graphical parameters par(op)
Computes the integrated EMG, with or without reset points.
integration(data, channel, reset = FALSE, reset.criteria = c("samples", "time", "value"), vreset, units, data.name)
integration(data, channel, reset = FALSE, reset.criteria = c("samples", "time", "value"), vreset, units, data.name)
data |
an ‘emg’ object, usually rectified, a moving averaged rectified EMG or a computed envelope of an EMG. |
channel |
in case of multi-channel data, |
reset , reset.criteria
|
if |
vreset |
a value to determine the reset points in an EMG, see Details. |
units |
a character vector specifying the units (usually "mV.s") of the integrated EMG data. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
If reset=FALSE
, the integrated EMG is the cumulative sum of the values in data
. If reset=TRUE
, the cumulative sum is reset to zero at some points, which are determined based on the value of reset.criteria
and vreset
:
reset.criteria = samples
: reset points are located every vreset
samples.
reset.criteria = time
: reset points are located every vreset
seconds.
reset.criteria = value
: reset points appear every time a value vreset
is reached in the cumulative sum.
An ‘iemg’ object storing the integrated EMG.
J.A. Guerrero [email protected]
Winter D.A., Rau G., Kadefors R., Broman H., Deluca C.J. (1980) Units, Terms, and Sandards in the Reporting of EMG Research: A Report by the AdHoc Committee of the International Society of Electrophysiology and Kinesiology.
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 2)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Full-wave rectified EMG emgr <- rectification(emgx, rtype = "fullwave") # Integration of the full-wave rectified EMG without reset points emgi1 <- integration(emgr, reset = FALSE) plot(emgi1, main = "Integrated EMG (no reset)") # Integration of the full-wave rectified EMG with reset points every # 200 samples emgi2 <- integration(emgr, reset = TRUE, reset.criteria = "samples", vreset = 200) plot(emgi2, main = "Integrated EMG (with reset)") # Integration of the full-wave rectified EMG with a reset point each # time the value 200 is reached emgi3 <- integration(emgr, reset = TRUE, reset.criteria = "value", vreset = 200) plot(emgi3, main = "Integrated EMG (with reset)") # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 2)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Full-wave rectified EMG emgr <- rectification(emgx, rtype = "fullwave") # Integration of the full-wave rectified EMG without reset points emgi1 <- integration(emgr, reset = FALSE) plot(emgi1, main = "Integrated EMG (no reset)") # Integration of the full-wave rectified EMG with reset points every # 200 samples emgi2 <- integration(emgr, reset = TRUE, reset.criteria = "samples", vreset = 200) plot(emgi2, main = "Integrated EMG (with reset)") # Integration of the full-wave rectified EMG with a reset point each # time the value 200 is reached emgi3 <- integration(emgr, reset = TRUE, reset.criteria = "value", vreset = 200) plot(emgi3, main = "Integrated EMG (with reset)") # reset graphical parameters par(op)
Loads ABFv1.0 files containing data from electrophysiological recordings, as created by Axon Instruments/Molecular Devices software such as AxoTape(TM) and AxoScope(TM).
loadABF1(filename, const = 0.00489615)
loadABF1(filename, const = 0.00489615)
filename |
name of the ABF file to load. |
const |
a multiplier to obtain the value represented in each datum (see ‘References’). |
Loads electrophysiology data from Version 1.0 ABF files, as created by software like AxoTape and AxoScope. The routine only loads the data section and some parts of the header to know how many channels are represented in the data.
Returns an object of class ‘emg’.
To load an Axon ABFv2.x file, please use the R package abf2.
J.A. Guerrero [email protected]
Axon(TM) Binary File Format (ABF): User Guide. http://mdc.custhelp.com/euf/assets/software/FSP_ABFHelp_2.03.pdf
Half-precision floating-point format (2015, June 26). In Wikipedia, The Free Encyclopedia. Retrieved July 9, 2015, https://en.wikipedia.org/w/index.php?title=Half-precision_floating-point_format&oldid=668770694
## Not run: ## Local path to sample data file path <- paste(system.file("extdata", package = "biosignalEMG"), "/96627009.DAT", sep = "") ## Load and show the data emg <- loadABF1(path) plot(emg) ## End(Not run)
## Not run: ## Local path to sample data file path <- paste(system.file("extdata", package = "biosignalEMG"), "/96627009.DAT", sep = "") ## Load and show the data emg <- loadABF1(path) plot(emg) ## End(Not run)
Lowpass filter an EMG signal.
lowpass(data, channel, cutoff = 50, n = 5, data.name)
lowpass(data, channel, cutoff = 50, n = 5, data.name)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
cutoff |
cutoff frequency in Hertz for the lowpass filter. |
n |
filter order for the lowpass filter. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
This procedure performs a lowpass filtering to the EMG signal with delay correction.
An ‘emg’ object which contains the filtered EMG.
This procedure only uses a butterworth type filter of order n
. In order to apply a different type of filter, please see the documentation of the ‘signal’ package.
J.A. Guerrero [email protected]
dcbiasremoval
, whitening
, highpass
# This example computes the LE-envelope using the lowpass routine # Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Compute the rectified signal x_rect <- rectification(x) # Filter the rectified signal y <- lowpass(x_rect, cutoff = 100) # change graphical parameters to show multiple plots op <- par(mfrow = c(3, 1)) # plot the original channel, the filtered channel and the # LE-envelope plot(x, channel = 1, main = "Original channel") plot(x_rect, main = "Rectified channel") plot(y, main = "LE-envelope") # reset graphical parameters par(op)
# This example computes the LE-envelope using the lowpass routine # Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Compute the rectified signal x_rect <- rectification(x) # Filter the rectified signal y <- lowpass(x_rect, cutoff = 100) # change graphical parameters to show multiple plots op <- par(mfrow = c(3, 1)) # plot the original channel, the filtered channel and the # LE-envelope plot(x, channel = 1, main = "Original channel") plot(x_rect, main = "Rectified channel") plot(y, main = "LE-envelope") # reset graphical parameters par(op)
Smooths an EMG by taking local averages.
movingaverage(data, channel, wsize, units = c("samples", "time"), data.name)
movingaverage(data, channel, wsize, units = c("samples", "time"), data.name)
data |
an ‘emg’ object, usually rectified. |
channel |
in case of multi-channel data, |
wsize , units
|
determines the length of the moving window that is used to calculate the local averages of the data. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
The moving average is a running average computed over a moving window over the length of the EMG. Usually, the EMG signal is first rectified due that, generally, the mean value of an EMG signal is zero.
The window length is the double of the value of wsize
in samples. The units
of the window size could be in number of samples ("samples") or in seconds ("time").
An ‘emg’ object containing the moving-averaged EMG.
J.A. Guerrero [email protected]
Konrad P. (2005) The ABC of EMG: A Practical Introduction to Kinesiological Electromyography. Version 1.0, Noraxon INC. USA.
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Compute the moving average of the rectified EMG emgr <- rectification(emgx, rtype = "fullwave") emgma <- movingaverage(emgr, wsize = 30, units = "samples") plot(emgma, main = "Moving average of the rectified EMG") # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Compute the moving average of the rectified EMG emgr <- rectification(emgx, rtype = "fullwave") emgma <- movingaverage(emgr, wsize = 30, units = "samples") plot(emgma, main = "Moving average of the rectified EMG") # reset graphical parameters par(op)
These quantities measure different aspects of the accuracy in the determination of activity changes of an electric signal.
ANDP(b, bE) MNChPD(b, bE) PCE(b, bE) PR(b, bE, t) TD(b, bE, t)
ANDP(b, bE) MNChPD(b, bE) PCE(b, bE) PR(b, bE, t) TD(b, bE, t)
b |
reference vector (target values) indicating for each position if the datum corresponds to a silence phase (0) or an active phase (1 or a greater integer indicating the level of activation). |
bE |
detected vector (output of an automatic detector) indicating for each position if the datum corresponds to a silence phase (0) or an active phase (1 or a greater integer indicating the level of activation). |
t |
tolerance value (see Details). |
These quality measures are defined as
ANDP | The absolute difference of the number of detected phases and the actual number of pahses |
MNChPD | The mean of the distances of each detected change-point to the nearest actual change-point |
PCE | The percentage of incorrectly classified points (silence-activity) |
TD | temporal deviation |
PR | computes the true positive ratio (TPR) and the false positive ratio (FPR). |
TD
and PR
depends on the value of t
, which is a tolerance for the difference between the calculated and exact changepoints.
See Guerrero et.al. (2014) for details on the computation of these measures.
ANDP, MNChPD, PCE, TD: a numeric value. PR: a list of two numeric values (TPR and FPR).
The parameter t
should be adjusted in terms of the sampling rate of the EMG.
J.A. Guerrero [email protected]
Guerrero J.A., Macias-Diaz J.E. (2014) A computational method for the detection of activation/deactivation patterns in biological signals with three levels of electric intensity. Math. Biosci. 248, 117–127.
Pistohl T., Schmidt T.S.B., Ball T., Schulze-Bonhage A., Aertsen A., Mehring C. (2013) Grasp detection from human ECoG during natural reach-to-grasp movements. PLoS ONE 8
onoff_bonato
, onoff_singlethres
# Simulate 10 seconds of an EMG emgx <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") # Detect the phases of activation in emgx b_bonato <- onoff_bonato(emgx, sigma_n = 0.05, m = 10, minL = 30) b_singlet <- onoff_singlethres(emgx, t = 0.2) # Compute the quality measures qm_bonato <- c(ANDP(b_bonato, emgx$on.off), MNChPD(b_bonato, emgx$on.off), PCE(b_bonato, emgx$on.off), PR(b_bonato, emgx$on.off, t = 10), TD(b_bonato, emgx$on.off, t = 10)) qm_singlet <- c(ANDP(b_singlet, emgx$on.off), MNChPD(b_singlet, emgx$on.off), PCE(b_singlet, emgx$on.off), PR(b_singlet, emgx$on.off, t = 10), TD(b_singlet, emgx$on.off, t = 10)) res <- as.matrix(cbind(qm_bonato, qm_singlet)) rownames(res) <- c("ANDP", "MNChPD", "PCE", "TPR", "FPR", "TD") print(res)
# Simulate 10 seconds of an EMG emgx <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") # Detect the phases of activation in emgx b_bonato <- onoff_bonato(emgx, sigma_n = 0.05, m = 10, minL = 30) b_singlet <- onoff_singlethres(emgx, t = 0.2) # Compute the quality measures qm_bonato <- c(ANDP(b_bonato, emgx$on.off), MNChPD(b_bonato, emgx$on.off), PCE(b_bonato, emgx$on.off), PR(b_bonato, emgx$on.off, t = 10), TD(b_bonato, emgx$on.off, t = 10)) qm_singlet <- c(ANDP(b_singlet, emgx$on.off), MNChPD(b_singlet, emgx$on.off), PCE(b_singlet, emgx$on.off), PR(b_singlet, emgx$on.off, t = 10), TD(b_singlet, emgx$on.off, t = 10)) res <- as.matrix(cbind(qm_bonato, qm_singlet)) rownames(res) <- c("ANDP", "MNChPD", "PCE", "TPR", "FPR", "TD") print(res)
Automatic detection algorithm to determine the times at which muscles “turn on” (activity periods) and “turn off” (silence periods) in an EMG signal.
onoff_bonato(data, channel, sigma_n, Pfa = 0.05, m = 5, r0 = 1, minL = 15, data.name)
onoff_bonato(data, channel, sigma_n, Pfa = 0.05, m = 5, r0 = 1, minL = 15, data.name)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
sigma_n |
standard deviation of the baseline noise (need to be estimated). |
Pfa |
false-alarm probability (see ‘Details’). |
m |
number of samples observed to perform the detection. |
r0 |
minimum number of samples out of |
minL |
minimum length allowed of the detected phases. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
This technique of detection consists of selecting a initial threshold (such that the probability of false alarm is Pfa
) and then observing m
successive samples: if
at least r0
out of the m
successive samples are above the threshold the presence of the signal is acknowledged.
A numeric vector with values 0 (silence) and 1 (activity).
The default values of m
and minL
where choosen for a sampling rate of 500Hz.
J.A. Guerrero [email protected]
Bonato P., D'Alessio T. and Knaflitz M. (1998) A statistical method for the measurement of muscle activation intervals from surface myoelectric signal during gait. IEEE Transactions on Biomedical Engineering 45 (3), 287–299. ISSN 0018–9294.
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Estimate 'sigma_n' from the last 200 samples (only baseline noise) sigma_n <- sd(tail(x$values, 200)) # Detect the phases of activation in x b <- onoff_bonato(x, sigma_n = sigma_n, m = 10, minL = 30) # Plot 'x' and the detected phases plot(x, main = "Sample EMG") plot(b, type = "l", main = "Detected phases (Bonato's method)") # reset graphical parameters par(op)
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Estimate 'sigma_n' from the last 200 samples (only baseline noise) sigma_n <- sd(tail(x$values, 200)) # Detect the phases of activation in x b <- onoff_bonato(x, sigma_n = sigma_n, m = 10, minL = 30) # Plot 'x' and the detected phases plot(x, main = "Sample EMG") plot(b, type = "l", main = "Detected phases (Bonato's method)") # reset graphical parameters par(op)
Automatic detection algorithm to determine the times at which muscles “turn on” (activity periods) and “turn off” (silence periods) in an EMG signal.
onoff_singlethres(data, channel, eemg, t = 0.05, data.name)
onoff_singlethres(data, channel, eemg, t = 0.05, data.name)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
eemg |
an ‘emg’ object containing an envelope. |
t |
a threshold value to determine if a datum reresent activity (above the threshold) or silence (below the threshold) in a signal. |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
In this procedure, on and off time estimation is determined by the times at which the envelope of the signal (eemg
or determined using envelope
) exceeds a threshold.
A numeric vector with values 0 (silence) and 1 (activity).
J.A. Guerrero [email protected]
Rose W. (2014) Electromyogram Analysis. Mathematics and Signal Processing for Biomechanics. http://www.udel.edu/biology/rosewc/kaap686/
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Detect the phases of activation in x b <- onoff_singlethres(x, t = 0.1) # Plot 'x' and the detected phases plot(x, main = "Sample EMG") plot(b, type = "l", main = "Detected phases (single thresholding)") # reset graphical parameters par(op)
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Detect the phases of activation in x b <- onoff_singlethres(x, t = 0.1) # Plot 'x' and the detected phases plot(x, main = "Sample EMG") plot(b, type = "l", main = "Detected phases (single thresholding)") # reset graphical parameters par(op)
Computes local statistics "f" of each phase on an EMG signal. The phases are defined by the contiguos points that have the same class.
phasestats(data,class,f)
phasestats(data,class,f)
data |
an ‘emg’ object. |
class |
a vector that indicates the class of each point in data. |
f |
A function that computes the desired local statistic. |
class is usually the result of a detection step (0=not active, 1=active). "f" could be the mean, standard deviaton, sum, length, etc.
An object storing the local statistics and the class of each value.
J.A. Guerrero [email protected]
None
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Detect the phases of activation in x b <- onoff_singlethres(x, t = 0.1) # Computes the length of the detected phases plengths<-phasestats(x,b,length) plengths # Computes the mean of the values within the detected phases pmeans<-phasestats(x,b,mean) pmeans # Only show the means of the active phases pmeans$stats[names(pmeans$stats)==1]
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Detect the phases of activation in x b <- onoff_singlethres(x, t = 0.1) # Computes the length of the detected phases plengths<-phasestats(x,b,length) plengths # Computes the mean of the values within the detected phases pmeans<-phasestats(x,b,mean) pmeans # Only show the means of the active phases pmeans$stats[names(pmeans$stats)==1]
Obtains the full-wave or half-wave rectification of an EMG.
rectification(data, channel, rtype = c("fullwave", "halfwave"), data.name, ...)
rectification(data, channel, rtype = c("fullwave", "halfwave"), data.name, ...)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
rtype |
a string indicating if the rectification is full-wave ("fullwave", default) or half-wave ("halfwave"). |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
... |
additional arguments to be passed to the generic function. |
A full-wave rectified EMG is obtained by computing the absolute value of the raw signal; In half wave rectification, the positive values are passed, while the negatives values are blocked (set to zero).
Rectification is mainly used as a pre-proccessing step before another process like averaging or computing the envelope of the signal.
An ‘emg’ object which contains the rectified EMG.
J.A. Guerrero [email protected]
Konrad P. (2005) The ABC of EMG: A Practical Introduction to Kinesiological Electromyography. Version 1.0, Noraxon INC. USA.
emg
, dcbiasremoval
, syntheticemg
# change graphical parameters to show multiple plots op <- par(mfrow = c(3, 1)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Full-wave rectified EMG emgr1 <- rectification(emgx, rtype = "fullwave") plot(emgr1, main = "Full-wave rectified EMG") # Half-wave rectified EMG emgr2 <- rectification(emgx, rtype = "halfwave") plot(emgr2, main = "Half-wave rectified EMG") # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(3, 1)) # Simulate 5 seconds of an EMG emgx <- syntheticemg(n.length.out = 5000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emgx, main = "Synthetic EMG") # Full-wave rectified EMG emgr1 <- rectification(emgx, rtype = "fullwave") plot(emgr1, main = "Full-wave rectified EMG") # Half-wave rectified EMG emgr2 <- rectification(emgx, rtype = "halfwave") plot(emgr2, main = "Half-wave rectified EMG") # reset graphical parameters par(op)
Creates a synthetic EMG based on a simple heteroscedastic model.
syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 0, units = "", data.name = "Synthetic EMG")
syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 0, units = "", data.name = "Synthetic EMG")
n.length.out |
number of observations. |
on.sd |
Standard deviation of the random values during an active phase. |
on.duration.mean |
mean lengths of active phases in number of samples. |
on.duration.sd |
standard deviation of lengths of active phases in number of samples. |
off.sd |
standard deviation of the random values during an silence phase (i.e. for the baseline noise). |
off.duration.mean |
mean lengths of silence phases in number of samples. |
off.duration.sd |
standard deviation of lengths of silence phases in number of samples. |
on.mode.pos |
a value between 0 (beginning of the active phase) and 1 (end of the active phase) indicating the relative position in which the maximum amplitude of an active phase will be located. |
shape.factor |
shape parameter (recommended values between 0 and 2). |
samplingrate |
sampling rate associated to the synthetic EMG. |
units |
units associated to the synthetic EMG. |
data.name |
a string specifying the name of the variable which will appears on the plots. |
A random synthetic EMG signal is generated using an heteroscedastic Gaussian model. There are two parameters that control the amplitude of the active and silence phases (on.sd
and off.sd
), two that control the (random) length of the active phases (on.duration.mean
and on.duration.sd
), two that control the (random) length of the silence phases (off.duration.mean
and off.duration.sd
) and two that control the shape of the burst during an active phase (on.mode.pos
and shape.factor
). A binary vector stores which samples are associated to an active phase for test purposes.
A derived ‘emg’ object which also contains a binary vector on.off
to indicate which samples correspond to an active phase (1) and which to a silence phase (0).
J.A. Guerrero [email protected]
Esquivel M.E., Guerrero J.A., Macias-Diaz J.E. (2010) Activity pattern detection in electroneurographic and electromyogram signals through a heteroscedastic change-point method. Mathematical Biosciences 224(2) 109–117
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Simulate 10 seconds of an EMG emg1 <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emg1, main = "Synthetic EMG") # Simulate 10 seconds of an EMG (pulse trains) emg2 <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.5, shape.factor = 0, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emg2, main = "Synthetic EMG (pulse trains)") # reset graphical parameters par(op)
# change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # Simulate 10 seconds of an EMG emg1 <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.75, shape.factor = 0.5, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emg1, main = "Synthetic EMG") # Simulate 10 seconds of an EMG (pulse trains) emg2 <- syntheticemg(n.length.out = 10000, on.sd = 1, on.duration.mean = 350, on.duration.sd = 10, off.sd = 0.05, off.duration.mean = 300, off.duration.sd = 20, on.mode.pos = 0.5, shape.factor = 0, samplingrate = 1000, units = "mV", data.name = "Synthetic EMG") plot(emg2, main = "Synthetic EMG (pulse trains)") # reset graphical parameters par(op)
Decorrelates an EMG signal using an SVD decomposition of a covariance matrix.
whitening(data, channel, method = c("PCA", "ZCA"), k = 4, r = 1, data.name)
whitening(data, channel, method = c("PCA", "ZCA"), k = 4, r = 1, data.name)
data |
an ‘emg’ object. |
channel |
in case of multi-channel data, |
method |
the whitening method to be applied to the EMG signal: "PCA" (default) or "ZCA" (see ‘References’). |
k |
number of columns (see ‘Details’) to construct the covariance matrix. |
r |
column to be used as the whitened signal (see ‘Details’). |
data.name |
a string specifying the name of the variable which will appears on the plots. If empty or not provided is taken from the object given as |
Whitening an EMG signal is a preprocessing step that can improve amplitude estimation, onset activation detection and fecature classification.
A whitening transformation reduces autocorrelation within a signal.
The implemented methods are PCA and ZCA, both based on a SVD decomposition of a covariance matrix. The (artificial) matrix is constructed with k shifted versions of the EMG signal. The result is then an matrix with k
columns. The output of the whitening procedure is (usually) the first column (r=1
).
An ‘emg’ object storing the whitened EMG.
The output is not fully whitened. The method decorrelates the columns of the artificial matrix, which contains a shifted version of the signal. At the end only one column (which can be autocorrelated) is taken as the output. Also, it works better when the sampling rate is high (low sampling rates tend to produce decorrelated samples).
J.A. Guerrero [email protected]
Implementing PCA/Whitening http://ufldl.stanford.edu/wiki/index.php/Implementing_PCA/Whitening
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Whitening x y <- whitening(x) # change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # plot the original channel and the corresponding whitened channel plot(x, main = "Original channel") plot(y, main = "Whitened channel") # reset graphical parameters par(op)
# Load a data.frame with EMG data data(emg95306000) # Coerce a data.frame into an 'emg' object x <- as.emg(emg95306000, samplingrate = 1000, units = "mV") # Whitening x y <- whitening(x) # change graphical parameters to show multiple plots op <- par(mfrow = c(2, 1)) # plot the original channel and the corresponding whitened channel plot(x, main = "Original channel") plot(y, main = "Whitened channel") # reset graphical parameters par(op)