I'm new to signal processing and try to analyze EMG data from pectoralis major and other respiratory muscles. Unfortunately, there are strong ECG artifacts in all recordings and I don't know how to remove them from my data.

My data looks like this:

Example of EMG data

In my experiment, there are two expected EMG-events, that should be at around second 2 and 8 of the recorded data:

Expected EMG-events

I'm working with python and matlab and couldn't find code-examples for this specific problem.

My sampling rate is 4000 Hz. Here is an example of the EMG-data.

Thanks a lot for your help!


1 Answer 1


Here is principal component analysis of the data you supplied. PCA will extract the features within the signal as is done in picture 1.

Note that the signal will be broken down as it is presented in picture 2 from the paper in 3 (page 15). To remove, just note that most of the principal components look like they come from the ecg data, so lets just take all the eigenvectors after 10 and project them onto our signal and add them up to get emg data (see picture 4). I'm not entirely sure what the emg data is suppose to look like, but this looks close to diaphragm emg data I see on google images. Try excluding even more eigenvectors to see if you get what you are looking for.

PCA Breakdown

    close all
    clear all
    H = csvread('\example.csv');
    %regroup data into snapshots of the signal
    %to treat as a group of random processes
    l = 2710
    Z = (H(1:l*10));
    X = reshape(Z,[l, 10]);
    RV = X*X'/length(X)
    %eigen decomposition
    [U,D,V] = svd(RV); 
    for i  = 1:12
    xx0 = V(:,i).*Z(1:l);
    strr = sprintf('principal component: %d', i);
    sig = 0; 
    for i = 11:length(V)
      sig = sig + V(:,i).*Z(1:l);
    title('Emg data?')
    title('Principal component 11, emg?')
    title('Principal component 12, emg?')
  • $\begingroup$ Thanks a lot for your detailed explanation – the emg data looks perfect! However, trying to use the provided code in Matlab (R2016b) I receive the following error: >> EMG_Filter Error: File: EMG_Filter.m Line: 32 Column: 12 Illegal use of reserved keyword "end". $\endgroup$
    – sarahp
    Oct 5, 2018 at 22:15
  • $\begingroup$ woops I edited the code to fix it. the 'end' in line 32 should have been length(V) $\endgroup$ Oct 5, 2018 at 22:22
  • $\begingroup$ also added figures of principal component 11 & 12, you should check these out. They are probably what you are looking for instead of the signal I constructed as the addition of all eigenvectors after 10. $\endgroup$ Oct 5, 2018 at 22:42
  • $\begingroup$ Thanks for your last adjustments. I took a look at the data and don't understand the resulting amount of data points (the sampling rate of the resulting signal). The resulting signal has 2709 values, the original signal 40000. Maybe this is a stupid question, but which timeframe does the resulting signal represent? In my experiment, there are two expected emg-events, that should be at around second 2 and 8 of the recorded data (see added image in my question). $\endgroup$
    – sarahp
    Oct 6, 2018 at 8:45
  • $\begingroup$ I basically took 'snapshots' as they did in the figure from the paper I linked. 2710 samples encompassed 1 ecg signal from your data. I then cleaned only one of these up Z(1:l) by projecting it onto the principal component, V(:,11).*Z(1:l). You can extend the principal component over your entire signal by looping over all l-length (2710) snapshots of H the code. i.e. V(:,11).*H(1:l), V(:,11).*H(l+1, 2*l+1), etc... $\endgroup$ Oct 6, 2018 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.