THG_FASTER_2_epoch_artifacts_20140302.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function [index parm zval] = THG_FASTER_2_epoch_artifacts_20140302(cfg,data)
  2. %% defaults
  3. if ~isfield(cfg,'criterion'); criterion = 3; else criterion = cfg.criterion; end
  4. if ~isfield(cfg,'recursive'); recursive = 1; else recursive = strcmp(cfg.recursive,'yes'); end
  5. % overall mean (calculation adopted from FASTER)
  6. alltmp = zeros([size(data.trial{1}) length(data.trial)]);
  7. for t = 1:length(data.trial)
  8. alltmp(:,:,t) = data.trial{t};
  9. end; clear t
  10. means = mean(mean(alltmp,2),3);
  11. %% loop trials
  12. for t = 1:length(data.trial)
  13. % trial data
  14. tmp = data.trial{t}';
  15. %% amplitude range
  16. parm.epoch_amp(1,t) = mean(max(tmp)-min(tmp));
  17. %% variance
  18. parm.epoch_var(1,t) = mean(var(tmp,1));
  19. %% channel deviation
  20. parm.epoch_dev(1,t) = mean(abs(mean(tmp)' - means));
  21. end; clear t
  22. %% zscores
  23. zval.epoch_amp = zscore(parm.epoch_amp);
  24. zval.epoch_var = zscore(parm.epoch_var);
  25. zval.epoch_dev = zscore(parm.epoch_dev);
  26. %% find outlier
  27. % temporary zscores
  28. tmpz = zval;
  29. % amplitude range outlier
  30. tmpz.epoch_amp = cm_outlier2nan_20140311(tmpz.epoch_amp,'>',criterion,recursive);
  31. % variance outlier
  32. tmpz.epoch_var = cm_outlier2nan_20140311(tmpz.epoch_var,'>',criterion,recursive);
  33. % channel deviation outlier
  34. tmpz.epoch_dev = cm_outlier2nan_20140311(tmpz.epoch_dev,'>',criterion,recursive);
  35. %% mark outlier
  36. index = find( isnan(tmpz.epoch_amp) | isnan(tmpz.epoch_var) | isnan(tmpz.epoch_dev) );