THG_automatic_artifact_correction_trials_20170922.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function [data index] = THG_automatic_artifact_correction_trials_20170922(data)
  2. %% preset config
  3. cfg.criterion = 3;
  4. cfg.recursive = 'no';
  5. %% create index for trials to keep
  6. index = 1:length(data.trial);
  7. %% repeat exclusion of trials
  8. check = 0;
  9. while check == 0;
  10. %% get artifact contaminated epoch by kurtosis, low & high frequency artifacts
  11. [indexA parmA zvalA] = cm_MWB_channel_x_epoch_artifacts_20170922(cfg,data);
  12. %% get artifact contaminated epochs by FASTER
  13. [indexB parmB zvalB] = THG_FASTER_2_epoch_artifacts_20140302(cfg,data);
  14. %% delete trials
  15. % collect bad trials
  16. badtrl = unique([indexA.t; indexB]);
  17. if prod(size(badtrl)) ~= 0
  18. % define trials to keep
  19. trials = 1:length(data.trial);
  20. trials(badtrl) = [];
  21. % config for deleting trials
  22. tmpcfg.trials = trials;
  23. tmpcfg.channel = 'all';
  24. % update index
  25. index(badtrl) = [];
  26. % remove trials
  27. data = ft_preprocessing(tmpcfg,data);
  28. % clear variables
  29. clear *A *B badtrl trials tmpcfg labels
  30. else
  31. check = 1;
  32. % clear variables
  33. clear *A *B
  34. end
  35. end