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 eigvectors 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.
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]);[![enter image description here][5]][5]
RV = X*X'/length(X)
%eigen decomposition
[U,D,V] = svd(RV);
figure
stem(diag(D))
title('eigenvalues')
%projection
figure
for i = 1:12
xx0 = V(:,i).*Z(1:l);
subplot(4,3,i)
plot(-xx0)
strr = sprintf('principal component: %d', i);
title(strr)
end
sig = 0;
for i = 11:length(V)
sig = sig + V(:,i).*Z(1:l);
end
figure
plot(sig)
title('Emg data?')
figure
subplot(121)
plot(V(:,11).*Z(1:l))
title('Principal component 11, emg?')
subplot(122)
plot(V(:,12).*Z(1:l))
title('Principal component 12, emg?')