preproc_frequency_spectra_pfe.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. %% Load Ind mat files
  2. % calls accuplot_mini requiring the Accusleep from Zeke Barger
  3. % each mat file contains four animals channels 1-4 -> first animal channels 5-8 -> second animal etc.
  4. % ch 1 = visual cortex right side, ch 2 = superior colliculus right side
  5. % ch 3 = superior colliculus left side, ch 4 = visual cortex left side
  6. base_dir=uigetdir(pwd); % point to directory of matfiles
  7. mat=dir(fullfile(base_dir,'*.mat')); % list of files
  8. nfiles=length(mat);
  9. %%
  10. % initiates arrays for visual cortex (VC) and superior colliculus (SC)
  11. VC=[];
  12. SC=[];
  13. for thisF=1:nfiles
  14. in_mat=fullfile(base_dir,mat(thisF).name);
  15. data=load(in_mat);
  16. EEG=data.d; % d1,d2,d3,d4 (four animals per file) EEG=data x chan
  17. spectra=[];
  18. %loop for channels 1:4
  19. %accuplot function ==> G.spectrogram for each channel
  20. for ii=1:4
  21. [G,fAxis,showFreqs]=accuplot_mini(EEG, ii, 1000); %takes EEG, ch, fs
  22. % spektrum
  23. spe=mean(G.spectrogram,1);
  24. m=mean(spe);
  25. normSpe=spe/m; % normalisation to mean power
  26. %plot(fAxis(showFreqs),normSpe)
  27. spectra=cat(1,spectra,normSpe);
  28. end
  29. % division into VC and SC
  30. VC=cat(3,VC,spectra([1,4],:));
  31. SC=cat(3,SC,spectra([2,3],:));
  32. end
  33. %%
  34. % dividing each file into group_treatment
  35. KO_veh=[1,5,9,26,30,34,37,41,45,39,43,47,15,19,23,51,55,59,52,56,60,62,66,70,64,68,72,...
  36. 90,94,98,100,104,108,103,107,111,137,141,145,161,165,169,163,167,171];
  37. KO_pfe=[3,7,11,13,17,21,16,20,24,50,54,58,74,78,82,76,80,84,...
  38. 88,92,96,113,117,121,124,128,132,126,130,134,102,106,110,138,142,146,139,143,147,149,153,157,151,155,159];
  39. WT_veh=[28,32,36,38,42,46,14,18,22,49,53,57,61,65,69,...
  40. 89,93,97,91,95,99,112,116,120,114,118,122,127,131,135,150,154,158,160,164,168,162,166,170,172:174];
  41. WT_pfe=[2,6,10,4,8,12,25,29,33,27,31,35,40,44,48,63,67,71,73,77,81,75,79,83,85:87,...
  42. 115,119,123,125,129,133,101,105,109,136,140,144,148,152,156];
  43. %% Mean and figures
  44. mKOve_vc=mean(VC(:,:,KO_veh),3);
  45. mKOpf_vc=mean(VC(:,:,KO_pfe),3);
  46. mWTve_vc=mean(VC(:,:,WT_veh),3);
  47. mWTpf_vc=mean(VC(:,:,WT_pfe),3);
  48. figure(1)
  49. subplot(211)
  50. hold on
  51. plot(fAxis(showFreqs),mWTve_vc','k')
  52. plot(fAxis(showFreqs),mWTpf_vc','b')
  53. subplot(212)
  54. hold on
  55. plot(fAxis(showFreqs),mKOve_vc','k')
  56. plot(fAxis(showFreqs),mKOpf_vc','b')
  57. mKOve_sc=mean(SC(:,:,KO_veh),3);
  58. mKOpf_sc=mean(SC(:,:,KO_pfe),3);
  59. mWTve_sc=mean(SC(:,:,WT_veh),3);
  60. mWTpf_sc=mean(SC(:,:,WT_pfe),3);
  61. figure(2)
  62. subplot(211)
  63. hold on
  64. plot(fAxis(showFreqs),mWTve_sc','k')
  65. plot(fAxis(showFreqs),mWTpf_sc','b')
  66. subplot(212)
  67. hold on
  68. plot(fAxis(showFreqs),mKOve_sc','k')
  69. plot(fAxis(showFreqs),mKOpf_sc','b')
  70. % average of spectra
  71. %% save spectrum for each group
  72. s.VCko=VC(:,:,KO_veh);
  73. s.VCwt=VC(:,:,WT_veh);
  74. s.SCko=SC(:,:,KO_veh);
  75. s.SCwt=SC(:,:,WT_veh);
  76. s.VCkoP=VC(:,:,KO_pfe);
  77. s.VCwtP=VC(:,:,WT_pfe);
  78. s.SCkoP=SC(:,:,KO_pfe);
  79. s.SCwtP=SC(:,:,WT_pfe);
  80. path1='C:\Users\...'; % path to output
  81. IDs=strcat(path1,'\SSVEPspectra.mat'); % name of output file
  82. save(IDs, 's');