Figure_3.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. nTotalNumberOfChannels = 0;
  14. PSD_aversive = [];
  15. PSD_neutral = [];
  16. for nSubject = 1:9
  17. file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
  18. f = nix.File([strNIXFolderPath,filesep,file_name],nix.FileMode.ReadOnly);
  19. sectionSession = f.openSection('Session');
  20. all_trials = sectionSession.openProperty('Number of trials').values{1}.value;
  21. block = f.blocks{1};
  22. group_iEEG = block.openGroup('iEEG data');
  23. dataMacro = [];
  24. for nTrial = 1:all_trials
  25. dataArray_iEEG = group_iEEG.dataArrays{nTrial};
  26. striEEGLabels = dataArray_iEEG.dimensions{1}.labels;
  27. if(length(dataArray_iEEG.dataExtent)==2)
  28. tiEEG = (0:(double(dataArray_iEEG.dataExtent(2))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
  29. else
  30. tiEEG = (0:(double(dataArray_iEEG.dataExtent(1))-1))*dataArray_iEEG.dimensions{2}.samplingInterval+dataArray_iEEG.dimensions{2}.offset;
  31. end
  32. data_iEEG = dataArray_iEEG.readAllData;
  33. dataMacro.time{1,nTrial} = tiEEG;
  34. dataMacro.trial{1,nTrial} = data_iEEG;
  35. end
  36. dataMacro.label = striEEGLabels';
  37. dataMacro.fsample = 2000;
  38. %% Power spectrum with FieldTrip
  39. cfg = [];
  40. cfg.output = 'pow';
  41. cfg.method = 'mtmconvol';
  42. cfg.taper = 'hanning';
  43. cfg.keeptrials = 'yes';
  44. cfg.foi = logspace(log10(1),log10(100),30);
  45. cfg.foi = linspace( 1, 100 ,50);
  46. cfg.t_ftimwin = 5./cfg.foi; % length of time window = 0.5 sec
  47. cfg.toi = -5:0.1:24;
  48. cfg.trials = 2:2:17;
  49. TFR_face = ft_freqanalysis(cfg, dataMacro);
  50. cfg.trials = 1:2:17;
  51. TFR_land = ft_freqanalysis(cfg, dataMacro );
  52. ch = 1:length(TFR_land.label);
  53. ff = TFR_land.freq;
  54. pwr_face = squeeze(nanmean(TFR_face.powspctrm(:,ch,:,:)));
  55. pwr_land = squeeze(nanmean(TFR_land.powspctrm(:,ch,:,:)));
  56. psd_face = nanmean(pwr_face,length(size(pwr_face)));
  57. psd_land = nanmean(pwr_land,length(size(pwr_land)));
  58. PSD_aversive(nTotalNumberOfChannels+ch,:) = psd_face;
  59. PSD_neutral(nTotalNumberOfChannels+ch,:) = psd_land;
  60. nTotalNumberOfChannels = nTotalNumberOfChannels+ch(end);
  61. end
  62. %% Plot Figure 3
  63. fig = figure;
  64. fig.Units = 'centimeters';
  65. fig.Position(3:4) = [12,10];
  66. data = [PSD_aversive(chs,:);PSD_neutral(chs,:)];
  67. cval = {'Aversive','Neutral'};
  68. cind = [ones(nTotalNumberOfChannels/2,1)*1;ones(nTotalNumberOfChannels/2,1)*2];
  69. c = cval(cind);
  70. g = gramm('x',ff,'y',data,'color',c);
  71. custom_statfun = @(y)([10*log10(nanmean(y));
  72. 10*log10(nanmean(y))-nanstd(10*log10(nanmean(y)))/sqrt(8*6);
  73. 10*log10(nanmean(y))+nanstd(10*log10(nanmean(y)))/sqrt(8*6)]);
  74. g.stat_summary('setylim',true,'type',custom_statfun);
  75. g.set_names('x','Frequency (Hz)','y','Power (dB)','Color','');
  76. g.axe_property('XLim',[-4,105],'YLim',[-2,18],'YTick',0:4:16,'XColor','k','YColor','k','TickDir','out','TickLength',[0.02,0.0250],...
  77. 'FontName','Arial','FontSize',10);
  78. g.set_layout_options('Legend_Position',[0.7,0.7,0.25,0.3]);
  79. g.set_text_options('Font','Arial');
  80. g.set_color_options('map',[1,0,0;0,0,1],'n_color',2,'n_lightness',1);
  81. g.draw();
  82. g.legend_axe_handle.FontName = 'Arial';
  83. % Save figure
  84. print('-dpdf','-r600','-painters','Fig3.pdf');
  85. print('-dpng','-r600','-painters','Fig3.png');
  86. end