Figure_2.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function fig = Figure_2(file_path)
  2. % TO BE INCLUDED IN THE PATH
  3. % fieldtrip: fieldtrip-20191028 www.fieldtrip.org
  4. % shadeErrobar: https://nl.mathworks.com/matlabcentral/fileexchange/26311-raacampbell-shadederrorbar
  5. %
  6. % include plotting toolbox gramm: https://github.com/piermorel/gramm
  7. %
  8. chs = [1 3 5 6 8 10 12]; % healthy amygdalae
  9. chtot = 0;
  10. for nSubject=1:9
  11. file_name = sprintf('Data_Subject_%.2d_Session_01.h5',nSubject);
  12. f = nix.File([file_path,file_name],nix.FileMode.ReadOnly);
  13. sectionSession = f.openSection('Session');
  14. all_trials = sectionSession.openProperty('Number of trials').values{1}.value;
  15. block = f.blocks{1};
  16. group_iEEG = block.openGroup('iEEG data');
  17. for nTrial = 1:all_trials
  18. dataArray_iEEG = group_iEEG.dataArrays{nTrial};
  19. striEEGLabels = dataArray_iEEG.dimensions{1}.labels;
  20. tiEEG = (0:(double(max(dataArray_iEEG.dataExtent))-1))* ...
  21. dataArray_iEEG.dimensions{2}.samplingInterval ...
  22. + dataArray_iEEG.dimensions{2}.offset;
  23. data_iEEG = dataArray_iEEG.readAllData;
  24. dataMacro.time{1, nTrial} = tiEEG;
  25. dataMacro.trial{1, nTrial} = data_iEEG;
  26. end
  27. dataMacro.label = striEEGLabels';
  28. dataMacro.fsample = 2000;
  29. %% Power spectrum with fieldtrip
  30. cfg = [];
  31. cfg.output = 'pow';
  32. cfg.method = 'mtmconvol';
  33. cfg.taper = 'hanning';
  34. cfg.keeptrials = 'yes';
  35. cfg.foi = logspace(log10(1),log10(100),30);
  36. cfg.foi = linspace( 1, 100 ,50); % analysis 2 to 30 Hz in steps of 2 Hz
  37. % analysis 2 to 30 Hz in steps of 2 Hz
  38. cfg.t_ftimwin = 5./cfg.foi; % length of time window = 0.5 sec
  39. cfg.toi = -5:0.1:24;
  40. cfg.trials = 2:2:17;
  41. TFR_face = ft_freqanalysis(cfg, dataMacro);
  42. cfg.trials = 1:2:17;
  43. TFR_land = ft_freqanalysis(cfg, dataMacro );
  44. ch = 1:length(TFR_land.label);
  45. tt = TFR_land.time;
  46. ff = TFR_land.freq;
  47. pwr_face = squeeze(nanmean(TFR_face.powspctrm(:,ch,:,:)));
  48. pwr_land = squeeze(nanmean(TFR_land.powspctrm(:,ch,:,:)));
  49. psd_face = nanmean(pwr_face,length(size(pwr_face)));
  50. psd_land = nanmean(pwr_land,length(size(pwr_land)));
  51. PSD_face(chtot+ch,:) = psd_face;
  52. PSD_land(chtot+ch,:) = psd_land;
  53. chtot = chtot+ch(end);
  54. end
  55. %% plot Figure 2
  56. clear g
  57. %figure('Position',[100 100 800 350]);
  58. fig = figure;
  59. data = [PSD_face(chs,:); PSD_land(chs,:)];
  60. cval={'Aversive' 'Neutral'};
  61. cind= [ones(chtot/2, 1)*1; ones(chtot/2, 1)*2];
  62. c=cval(cind);
  63. g=gramm( 'x', ff, 'y', data, 'color',c);
  64. custom_statfun = @(y)([10*log10(nanmean(y));
  65. 10*log10(nanmean(y)) - nanstd(10*log10(nanmean(y)))/sqrt(8*6);
  66. 10*log10(nanmean(y)) + nanstd(10*log10(nanmean(y)))/sqrt(8*6)]);
  67. g.stat_summary('setylim', true, 'type', custom_statfun);
  68. g.set_names( 'x', 'Frequency [Hz]', 'y', 'Power [dB]' );
  69. g.draw();
  70. % shadedErrorBar(ff, 10*log10(nanmean(PSD_face(chs,:))), ...
  71. % (nanstd(10*log10(PSD_face(chs,:)))/sqrt(8*6)),'r');
  72. % hold on;
  73. % shadedErrorBar(ff, 10*log10(nanmean(PSD_land(chs,:))), ...
  74. % (nanstd(10*log10(PSD_land(chs,:)))/sqrt(8*6)),'b');
  75. %
  76. % xlabel('Frequency [Hz]')
  77. % ylabel('Power [dB]')
  78. %
  79. % text(60,14,'Neutral','fontsize',16,'color','b')
  80. % text(60,12,'Aversive','fontsize',16,'color','r')
  81. print('-dtiff','-r300','fig_2.tiff')