Fieldtrip has provide a automatic removing artifact method , we have done a test on the local data, in turn, it did not work as you expected , sometimes  badlly, Please visually checking for artifacts

the following code :

 

clear all

cfg=[];
cfg.dataset=’01_day1_post 20140303 1213.002.RAW';
cfg.trialdef.triallength =30;
cfg.trialdef.ntrials = Inf;
cfg=ft_definetrial(cfg);
data=ft_preprocessing(cfg);
%
% jump
cfg = [];
cfg.continuous = ‘yes';

% channel selection, cutoff and padding
cfg.artfctdef.zvalue.channel = ‘all';
cfg.artfctdef.zvalue.cutoff = 30;
cfg.artfctdef.zvalue.trlpadding = 0;
cfg.artfctdef.zvalue.artpadding = 0;
cfg.artfctdef.zvalue.fltpadding = 0;

% algorithmic parameters
cfg.artfctdef.zvalue.cumulative = ‘yes';
cfg.artfctdef.zvalue.medianfilter = ‘yes';
cfg.artfctdef.zvalue.medianfiltord = 9;
cfg.artfctdef.zvalue.absdiff = ‘yes';

% make the process interactive
cfg.artfctdef.zvalue.interactive = ‘yes';

[cfg, artifact_jump] = ft_artifact_zvalue(cfg,data);

%Muscle
cfg = [];
cfg.continuous = ‘yes';

% channel selection, cutoff and padding
cfg.artfctdef.zvalue.channel = ‘all';
cfg.artfctdef.zvalue.cutoff = 4;
cfg.artfctdef.zvalue.trlpadding = 0;
cfg.artfctdef.zvalue.fltpadding = 0;
cfg.artfctdef.zvalue.artpadding = 0.1;

% algorithmic parameters
cfg.artfctdef.zvalue.bpfilter = ‘yes';
cfg.artfctdef.zvalue.bpfreq = [110 140];
cfg.artfctdef.zvalue.bpfiltord = 9;
cfg.artfctdef.zvalue.bpfilttype = ‘but';
cfg.artfctdef.zvalue.hilbert = ‘yes';
cfg.artfctdef.zvalue.boxcar = 0.2;

% make the process interactive
cfg.artfctdef.zvalue.interactive = ‘yes';

[cfg, artifact_muscle] = ft_artifact_zvalue(cfg,data);

% EOG
cfg = [];
cfg.continuous = ‘yes';

% channel selection, cutoff and padding
cfg.artfctdef.zvalue.channel = ‘all';
cfg.artfctdef.zvalue.cutoff = 4;
cfg.artfctdef.zvalue.trlpadding = 0;
cfg.artfctdef.zvalue.artpadding = 0.1;
cfg.artfctdef.zvalue.fltpadding = 0;

% algorithmic parameters
cfg.artfctdef.zvalue.bpfilter = ‘yes';
cfg.artfctdef.zvalue.bpfilttype = ‘but';
cfg.artfctdef.zvalue.bpfreq = [1 15];
cfg.artfctdef.zvalue.bpfiltord = 4;
cfg.artfctdef.zvalue.hilbert = ‘yes';

% feedback
cfg.artfctdef.zvalue.interactive = ‘yes';

[cfg, artifact_EOG] = ft_artifact_zvalue(cfg,data);

% ECG
cfg = [];
cfg.continuous = ‘yes';

% channel selection, cutoff and padding
cfg.artfctdef.zvalue.channel=’all';
cfg.artfctdef.zvalue.cutoff=2;
cfg.artfctdef.zvalue.trlpadding = 0;
cfg.artfctdef.zvalue.artpadding = 0;
cfg.artfctdef.zvalue.fltpadding = 0;

% algorithmic parameters
cfg.artfctdef.zvalue.bpfilter=’yes';
cfg.artfctdef.zvalue.bpfreq=[5 30];
cfg.artfctdef.zvalue.hilbert=’yes';
% cfg.artfctdef.zvalue.artfctpeak=’yes';
cfg.artfctdef.zvalue.artfctpeakrange=[-.25 .5]; % save out 250ms prior and 500ms post ECG peak

% feedback
cfg.artfctdef.zvalue.interactive = ‘yes';

[cfg, artifact_ECG] = ft_artifact_zvalue(cfg,data);

 

cfg=[];
cfg.artfctdef.reject = ‘partial'; % this rejects complete trials, use ‘partial’ if you want to do partial artifact rejection
cfg.artfctdef.eog.artifact = artifact_EOG; %
cfg.artfctdef.jump.artifact = artifact_jump;
cfg.artfctdef.muscle.artifact = artifact_muscle;
cfg.artfctdef.ecg.artifact = artifact_ECG;
data_no_artifacts = ft_rejectartifact(cfg,data);

%run ica
cfg=[];
cfg.method=’runica';

datacomp=ft_componentanalysis(cfg,data_no_artifacts)
cfg=[];
cfg.viewmode=’component';
cfg.layout=’GSN128.sfp';
cfg.comment=’no';
ft_databrowser(cfg,datacomp);

 

 

After this process, we have no trials left, which means all trials has been considered as a artifact.

 

this’s really joking.

 

in the tutorial . there is a very good page talking about the walk though the Fieldtrip

it mentions as :

Introduction

Finding an appropriate approach to artifact rejection is not as simple as one might think. Every system, every experiment and even every subject will vary in number, magnitude and type of artifacts. Also, some researchers might be okay with just rejecting trials with any artifacts, some only if eye blinks come before a stimulus, while again others might want to correct for eye and movement artifacts by using an ICA approach. Furthermore, some artifacts, like spikes, might be easy to detect because of their signal properties, while others might be much harder to detect. For these reasons I believe one cannot do without visual inspection of the data. Only in very rare cases of very typical and well described artifacts, such as jumps from a specific MEG system, we think a full automatic artifact rejection is warranted. Besides all those rational considerations, manually going through your data early will also give you a certain ‘feeling’ of what your data is like.

Of course, in the end you would like to have certain standardized approach to your artifact rejection that will give you the best results possible. I don’t know if something like that exists and rather think everyone has his or her own personal preferences. Although seemingly rather time-consuming, I myself ended up with the following procedure. You need not follow it, it’s just a suggestion. It does give me the possibility of explaining some of the following steps in more detail. In particular it will explain a use of ft_databrowser, a recently added function which is not yet documented elsewhere.

  1. Visually inspect the dataset and mark those segments that contain obvious movements, (system) spikes or muscle artifacts, leaving in all but the most extreme eye artifacts.
  2. Reject the trials that contain artifacts.
  3. Decompose the data using ICA. Note that ICA can give very unreliable results when the data contains a lot of (correlated) noise. The cleaner the data is already, the better the ICA results.
  4. Find components clearly corresponding to eye blinks and saccades.
  5. Recompose data without those components.
  6. Go through data again visually and manually selects segments that still show any remaining artifacts, being from eye blinks, movements, etc.

I know this looks like a lot of work. However, it might pay off in the end when you are certain your data is clean and you do not have to go back to satisfy that slightly uneasy feeling that your results might ‘be all artifacts’. Of course they might still be, but at least you did everything you could.