multiplotTFR goes wrong

Sibylle Mohr s.mohr at PSY.GLA.AC.UK
Tue Nov 3 14:30:14 CET 2009


Dear Fieldtrippers,

I have a problem concerning multiplotTFR, which I did not have a couple of months ago:
I import 4 conditions (lexical match/lexical mismatch and stereotypical match / 
stereotypical mismatch). After doing a multitaper analysis for different frequencies I do a 
baseline correction using 'zscore' across the averaged trials for each condition. When I 
plot the resulting zscore corrected conditions using multiploTFR contrasting 'lexical 
mismatch' with 'lexical match' and afterwards 'stereotypical mismatch' with 'stereotypical 
match', it looks like the stereotypical conditions are almost the inverse plot of my lexical 
conditions. I always clear the cfg before I start a new plot. I also use cfg.interactive = 
'yes'. Any ideas why this is happening..?

I'll attach the scripts for the multitaper analysis, the baseline correction, and for the 
plotting.

Thanks,

Sibylle

-----------------------
MULTITAPER ANALYSIS

function hifreq_ana

% anaphora files: high frequencies

% BESA datafiles in one condition
filename_ana{1} = {
  'An1_sb1_lexmatch-export.dat'
  'An1_sb9_lexmatch-export.dat'
  'An1_sb13_lexmatch-export.dat'
  'An1_sb17_lexmatch-export.dat'
  'An1_sb21_lexmatch-export.dat'
  'An2_sb2_lexmatch-export.dat'
  'An2_sb6_lexmatch-export.dat'
  'An2_sb10_lexmatch-export.dat'
  'An2_sb18_lexmatch-export.dat'
  'An2_sb22_lexmatch-export.dat'
  'An3_sb3_lexmatch-export.dat'
  'An3_sb7_lexmatch-export.dat'
  'An3_sb11_lexmatch-export.dat'
  'An3_sb15_lexmatch-export.dat'
  'An3_sb23_lexmatch-export.dat'
  'An4_sb4_lexmatch-export.dat'
  'An4_sb8_lexmatch-export.dat'
  'An4_sb12_lexmatch-export.dat'
  'An4_sb16_lexmatch-export.dat'
  'An4_sb24_lexmatch-export.dat'
  };


 % BESA datafiles in the other condition
filename_ana{2} = {
  'An1_sb1_lexmis-export.dat'
  'An1_sb9_lexmis-export.dat'
  'An1_sb13_lexmis-export.dat'
  'An1_sb17_lexmis-export.dat'
  'An1_sb21_lexmis-export.dat'
  'An2_sb2_lexmis-export.dat'
  'An2_sb6_lexmis-export.dat'
  'An2_sb10_lexmis-export.dat'
  'An2_sb18_lexmis-export.dat'
  'An2_sb22_lexmis-export.dat'
  'An3_sb3_lexmis-export.dat'
  'An3_sb7_lexmis-export.dat'
  'An3_sb11_lexmis-export.dat'
  'An3_sb15_lexmis-export.dat'
  'An3_sb23_lexmis-export.dat'
  'An4_sb4_lexmis-export.dat'
  'An4_sb8_lexmis-export.dat'
  'An4_sb12_lexmis-export.dat'
  'An4_sb16_lexmis-export.dat'
  'An4_sb24_lexmis-export.dat'
  };

filename_ana{3} = {
  'An1_sb1_stermatch-export.dat'
  'An1_sb9_stermatch-export.dat'
  'An1_sb13_stermatch-export.dat'
  'An1_sb17_stermatch-export.dat'
  'An1_sb21_stermatch-export.dat'
  'An2_sb2_stermatch-export.dat'
  'An2_sb6_stermatch-export.dat'
  'An2_sb10_stermatch-export.dat'
  'An2_sb18_stermatch-export.dat'
  'An2_sb22_stermatch-export.dat'
  'An3_sb3_stermatch-export.dat'
  'An3_sb7_stermatch-export.dat'
  'An3_sb11_stermatch-export.dat'
  'An3_sb15_stermatch-export.dat'
  'An3_sb23_stermatch-export.dat'
  'An4_sb4_stermatch-export.dat'
  'An4_sb8_stermatch-export.dat'
  'An4_sb12_stermatch-export.dat'
  'An4_sb16_stermatch-export.dat'
  'An4_sb24_stermatch-export.dat'
  };


 % BESA datafiles in the other condition
filename_ana{4} = {
  'An1_sb1_stermis-export.dat'
  'An1_sb9_stermis-export.dat'
  'An1_sb13_stermis-export.dat'
  'An1_sb17_stermis-export.dat'
  'An1_sb21_stermis-export.dat'
  'An2_sb2_stermis-export.dat'
  'An2_sb6_stermis-export.dat'
  'An2_sb10_stermis-export.dat'
  'An2_sb18_stermis-export.dat'
  'An2_sb22_stermis-export.dat'
  'An3_sb3_stermis-export.dat'
  'An3_sb7_stermis-export.dat'
  'An3_sb11_stermis-export.dat'
  'An3_sb15_stermis-export.dat'
  'An3_sb23_stermis-export.dat'
  'An4_sb4_stermis-export.dat'
  'An4_sb8_stermis-export.dat'
  'An4_sb12_stermis-export.dat'
  'An4_sb16_stermis-export.dat'
  'An4_sb24_stermis-export.dat'
  };

ncond = length(filename_ana);
nsubj = length(filename_ana{1});


tmp = importdata('New_elect72.elp');

for j = 1:ncond
clear data

for i=1:nsubj
data = besa2fieldtrip(filename_ana{j}{i});
% % import electrode file and create electrode arrays
% % with coordinates in elp file
% % match channel and electrode names
data.label = tmp.textdata(:,2);

clear cfg;
cfg.foi             = [30:4:130];
numfoi              = length(cfg.foi);
cfg.t_ftimwin 		= zeros(1,numfoi);
cfg.t_ftimwin(:) 	= 0.25;
cfg.method          = 'mtmconvol';
cfg.output          = 'pow';
cfg.toi             = [-0.5:0.02:1.5];
cfg.taper           = 'dpss';
cfg.tapsmofrq 		= zeros(1,numfoi);
cfg.tapsmofrq(:) 	= 16;
cfg.keeptrials 		= 'yes';

freqhi              = freqanalysis(cfg,data);
% change from double to single precision to save space on the harddisk
single              = struct2single(freqhi);
save(sprintf('/analyse/12/Project0042/Gender_new/dat-
files_multitaper/anaphora/hi_freq_%d_%d.mat',j,i),'single');
clear single

end; % subject loop
end; % condition loop
exit; 
---------------------------------------

BASELINE CORRECTION SCRIPT

function allfreq_zscores

name = {'lex','lexmis','ster','stermis'};
ldir = '/analyse/12/Project0042/Gender_new/dat-files_multitaper/';
path = {'anaphora/','cataphora/'};

frq = {'lo','med'};
pathname = {'ana','cat'};
%pathname = {'cat'};
%................. LO AND MEDIUM FREQUENCY ANALYSIS

for p = 1:length(path)
    for f = 1:length(frq)
        for i = 1:length(name)
            load(sprintf('%s%s%s_%s.mat',ldir,path{p},frq{f},name{i}));
            for j = 1:20
if f == 1
            if i == 1
    freq = freqlo_lexmatch{j}; 
elseif i == 2
    freq = freqlo_lexmis{j}; 
elseif i == 3
    freq = freqlo_stermatch{j}; 
elseif i == 4
    freq = freqlo_stermis{j}; 
end;
elseif f == 2
if i == 1
    freq = freqmed_lexmatch{j}; 
elseif i == 2
    freq = freqmed_lexmis{j}; 
elseif i == 3
    freq = freqmed_stermatch{j}; 
elseif i == 4
    freq = freqmed_stermis{j};
end;
end;

double = struct2double(freq);
clear freq;

%... check if there is the trial-dimension or not
if length(size(double.powspctrm)) == 4
    double = freqdescriptives([],double);
end;

cfg = [];
cfg.baseline = [-0.5 0];
cfg.baselinetype = 'zscore';
freq = freqbaseline(cfg,double);
clear double

freqdes{j} = struct2single(freq);
clear freq
        end; % subject loop
        save(sprintf('%s%s_%s_z_%s.mat',ldir,pathname{p},frq{f},name{i}),'freqdes');
        clear freqdes
    end; % condition loop
end; % frequency loop
end; % path loop

%.................. HI FREQUENCY ANALYSIS

disp('SWITCHING TO HIGH FREQUENCIES')

for p = 1:length(path); %two different paths
for i = 1:length(name); %four different conditions
for j = 1:20 %(length of subjects)
    tmp=load(sprintf('%s%shi_freq_%d_%d.mat',ldir,path{p},i,j));

% convert to double before starting calculations
double              = struct2double(tmp.single);
clear freq

% average across trials using freqdescriptives
double               = freqdescriptives([],double);

% do baseline normalization across the AVERAGED trials (for normalization
% over SINGLE trials, switch around freqdescriptives and freqbaseline)
clear cfg;
cfg.baseline        = [-0.5 0];
cfg.baselinetype    = 'zscore';
fqhi                = freqbaseline(cfg,double);
clear double

freqdes{j} = struct2single(fqhi);
clear fqhi
end; % subject loop/ j-loop
%save freqdescriptives of 20 subjets (single precision) into one cell-array, and save that
%per condition.
save(sprintf('%s%s_hi_z_%s.mat',ldir,pathname{p},name{i}),'freqdes');
clear freqdes
end; % condition loop / i-loop
end; % path loop
exit;

--------------------------------------

PLOTTING SCRIPT

%.................HI FREQUENCY ANALYSIS PLOTS

clear all;
load(sprintf('cat_hi_z_lex.mat'));
hi_lmatch=freqdes;
clear freqdes

load(sprintf('cat_hi_z_lexmis.mat'));
hi_lmis=freqdes;
clear freqdes

load(sprintf('cat_hi_z_ster.mat'));
hi_smatch=freqdes;
clear freqdes

load(sprintf('cat_hi_z_stermis.mat'));
hi_smis=freqdes;
clear freqdes


clear grandhi1_lexmatch grandhi1_lmis grandhi1_smatch grandhi1_smis;
cfg = [];
grandhi1_lmatch = freqgrandaverage(cfg, hi_lmatch{:});
grandhi1_lmis = freqgrandaverage(cfg, hi_lmis{:});
grandhi1_smatch = freqgrandaverage(cfg, hi_smatch{:});
grandhi1_smis = freqgrandaverage(cfg, hi_smis{:});

clear avgdif_a;
clear avgdif_b;
avgdif_a = grandhi1_lmis;
avgdif_a.powspctrm = ((grandhi1_lmis.powspctrm - 
grandhi1_lmatch.powspctrm)./grandhi1_lmatch.powspctrm).*100;

avgdif_b = grandhi1_smis;
avgdif_b.powspctrm = ((grandhi1_smis.powspctrm - 
grandhi1_smatch.powspctrm)./grandhi1_smatch.powspctrm).*100;

clear cfg;
load('elec.mat');
% scale the electrodes to a realistic head size (in cm)
elec.pnt = 10*elec.pnt;
clear cfg;
cfg= [];
cfg.elec = elec;
cfg.colorbar = 'yes';
cfg.xparam = 'time';
cfg.yparam = 'freq';
cfg.zparam = 'powspctrm';
cfg.showlabels = 'yes';
cfg.layout = 'sibylle.lay';
cfg.interactive = 'yes';
cfg.title = 'lexical_conditions';
cfg.xlim = ([-0.5 1.5]);
cfg.ylim = [30 130];
%cfg.zlim = [-50 50];
figure; multiplotTFR(cfg, avgdif_a);
title('FreqHi Cata: lexical match vs. mismatch');

clear cfg;
cfg= [];
cfg.elec = elec;
cfg.colorbar = 'yes';
cfg.xparam = 'time';
cfg.yparam = 'freq';
cfg.zparam = 'powspctrm';
cfg.showlabels = 'yes';
cfg.layout = 'sibylle.lay';
cfg.interactive = 'yes';
cfg.title = 'lexical_conditions';
cfg.xlim = ([-0.5 1.5]);
cfg.ylim = [30 130];
%cfg.zlim = [-50  50];
figure; multiplotTFR(cfg, avgdif_b);
title('FreqHi Cata: stereotypicalmatch vs. mismatch');
--------------------------------

----------------------------------
The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also http://listserv.surfnet.nl/archives/fieldtrip.html and http://www.ru.nl/neuroimaging/fieldtrip.



More information about the fieldtrip mailing list