Figure_3.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. function fig = Figure_3( strNIXFolderPath )
  2. % Figure_3.m reproduces Figure 3 in the dataset publication
  3. % fig = Figure_3(strNIXFolderPath) reproduces Figure 3
  4. % strNIXFolderPath is the path of the folder with NIX files
  5. % fig is the figure handle
  6. %
  7. % Add the toolbox 'gramm' to the MATLAB path
  8. % The toolbox can be downloaded from https://github.com/piermorel/gramm
  9. %
  10. % Add the toolbox 'FieldTrip' to the MATLAB path
  11. % The toolbox can be downloaded from http://www.fieldtriptoolbox.org/download
  12. chs = [1 3 5 6 8 10 12]; % healthy amygdalae
  13. chtot = 0;
  14. for nSubject = 1:9
  15. file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
  16. f = nix.File([strNIXFolderPath,filesep,file_name],nix.FileMode.ReadOnly);
  17. sectionSession = f.openSection('Session');
  18. all_trials = sectionSession.openProperty('Number of trials').values{1}.value;
  19. block = f.blocks{1};
  20. group_iEEG = block.openGroup('iEEG data');
  21. dataMacro = [];
  22. for nTrial = 1:all_trials
  23. dataArray_iEEG = group_iEEG.dataArrays{nTrial};
  24. striEEGLabels = dataArray_iEEG.dimensions{1}.labels;
  25. if(length(dataArray_iEEG.dataExtent)==2)
  26. tiEEG = (0:(double(dataArray_iEEG.dataExtent(2))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
  27. else
  28. tiEEG = (0:(double(dataArray_iEEG.dataExtent(1))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
  29. end
  30. data_iEEG = dataArray_iEEG.readAllData;
  31. dataMacro.time{1,nTrial} = tiEEG;
  32. dataMacro.trial{1,nTrial} = data_iEEG;
  33. end
  34. dataMacro.label = striEEGLabels';
  35. dataMacro.fsample = 2000;
  36. %% Power spectrum with FieldTrip
  37. cfg = [];
  38. cfg.output = 'pow';
  39. cfg.method = 'mtmconvol';
  40. cfg.taper = 'hanning';
  41. cfg.keeptrials = 'yes';
  42. cfg.foi = logspace(log10(1),log10(100),30);
  43. cfg.foi = linspace( 1, 100 ,50);
  44. cfg.t_ftimwin = 5./cfg.foi; % length of time window = 0.5 sec
  45. cfg.toi = -5:0.1:24;
  46. cfg.trials = 2:2:17;
  47. TFR_face = ft_freqanalysis(cfg, dataMacro);
  48. cfg.trials = 1:2:17;
  49. TFR_land = ft_freqanalysis(cfg, dataMacro );
  50. ch = 1:length(TFR_land.label);
  51. tt = TFR_land.time;
  52. ff = TFR_land.freq;
  53. pwr_face = squeeze(nanmean(TFR_face.powspctrm(:,ch,:,:)));
  54. pwr_land = squeeze(nanmean(TFR_land.powspctrm(:,ch,:,:)));
  55. psd_face = nanmean(pwr_face,length(size(pwr_face)));
  56. psd_land = nanmean(pwr_land,length(size(pwr_land)));
  57. PSD_face(chtot+ch,:) = psd_face;
  58. PSD_land(chtot+ch,:) = psd_land;
  59. chtot = chtot+ch(end);
  60. end
  61. %% Plot Figure 3
  62. fig = figure;
  63. data = [PSD_face(chs,:); PSD_land(chs,:)];
  64. cval = {'Aversive' 'Neutral'};
  65. cind = [ones(chtot/2,1)*1;ones(chtot/2,1)*2];
  66. c = cval(cind);
  67. g = gramm('x',ff,'y',data,'color',c);
  68. custom_statfun = @(y)([10*log10(nanmean(y));
  69. 10*log10(nanmean(y))-nanstd(10*log10(nanmean(y)))/sqrt(8*6);
  70. 10*log10(nanmean(y))+nanstd(10*log10(nanmean(y)))/sqrt(8*6)]);
  71. g.stat_summary('setylim',true,'type',custom_statfun);
  72. g.set_names( 'x', 'Frequency [Hz]','y','Power [dB]');
  73. g.draw();
  74. % Save figure
  75. print('-dtiff','-r300','fig_3.tiff')
  76. end