clear all
ds = sprintf('/gs1/users/rajamoni/MEG_ds/AEDTPJOU_nback_20050422_01-f.ds')
cfg = [];
cfg.dataset = ds;
cfg.trialdef.eventtype  = '?';
definetrial(cfg);
cfg.trialdef.eventtype = 'r0';
cfg.trialdef.prestim  = 0.25;
cfg.trialdef.poststim = 0.25;
cfg = definetrial(cfg);
data = preprocessing(cfg)


%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
f1 = 1.; f2 = 60.0;
smo = 2.;
r = .75;
%cfg.channel            = 'all';
cfg.channel         = {'MEG','-MRF43', '-MRO13'};
cfg.latency            = [-0.25 0.25];
cfg.covariance         = 'yes';
cfg.covariancewindow   = [-0.0 0.25];
cfg.keeptrials         = 'yes';
%cfg.vartrllength       = 2; 
%cfg.blc                = 'no'
cfg.blcwindow          = [-0.25 0.25];
%cfg.bpfilter           = 'yes'
cfg.bpfreq             = [1 60];
%fg.bpfiltord          = 10
cfg.bpfilttype         = 'fir';   
%cfg.bpfilttype         = 'fir'   
[timelock] = timelockanalysis(cfg,data);

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cfg = [];
cfg.method   = 'lcmv';
cfg.grid.pos = [-10 -10 -2.75]; %arbitrary source location
cfg.singletrial = 'yes';
cfg.rawtrial    = 'no';
cfg.keepfilter  = 'yes';
cfg.keepmom     = 'yes';
cfg.hdmfile = strcat(ds, '/default.hdm');
%cfg.channel         = {'MEG','-MRF43', '-MRO13'};
%cfg.vol = vol;
[source] = sourceanalysis(cfg, timelock);

% extraction of single trial source signals

% the other method sqrt(x^2+y^2+z^2)
%for trial all trials
for i=1:66
  trial{i}=source.trial(i).mom{1};
  tr{i}=sqrt((sum(trial{i}.*trial{i})));
end;

