Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

getDSCSD.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. %get CSD of DSs
  2. %requires CSD Plotter https://github.com/espenhgn/CSDplotter
  3. %2021 Dino Dvorak, New York University, neuraldino@gmail.com
  4. %Dentate spikes and external control of hippocampal function,
  5. %Cell Reports, Volume 36, Issue 5, 2021,109497,ISSN 2211-1247,
  6. %https://doi.org/10.1016/j.celrep.2021.109497
  7. clear; close all; clc;
  8. addpath(genpath('/Users/dino/DATA/matlab/CSDplotter'));
  9. %directories
  10. drDS = 'DS/';
  11. drMAT = 'MAT_EEG/';
  12. drOUT = 'DS_CSD/';
  13. %input LFP file (channels x samples)
  14. fnEEG = '2016_09_30_PP12_334_PRETRAIN_BASE_eeg.mat';
  15. %load DS and LFP
  16. load([drDS fnEEG]);
  17. load([drMAT fnEEG]);
  18. %LFP channels
  19. Nchannels = size(eegData,1);
  20. %CSD properties
  21. h = 50e-6; %inter-electrode distance meters
  22. ex_cond = 0.3; %external conductivity S/m
  23. top_cond = 0.3; %S/m
  24. diam = 0.5e-3; %mm
  25. gauss_sigma = 0.05e-3; %mm
  26. filter_range = 5*gauss_sigma; % numeric filter must be finite in extent
  27. dt = 0.5; %sampling time ms (for 2k);
  28. scale_plot = 1; %focus
  29. max_plot = 0;
  30. CSDres = 200; %CSD resolution (fixed)
  31. methodSpline = 1; %CSD method
  32. if Nchannels == 32
  33. el_pos = 0.1:0.05:1.65; %our tetrode distances (array)
  34. el_pos = el_pos*1e-3; %mm
  35. elseif Nchannels == 16
  36. el_pos = 0.1:0.05:0.85;
  37. el_pos = el_pos*1e-3; %mm
  38. end
  39. %create filter for CSD filtering
  40. eegFS = 2000;
  41. [b, gd] = getFIRbandpass( 5,200,4,40,eegFS );
  42. winLen = 10; %window for CSD extraction
  43. %filter
  44. eegF = filter(b,1,eegData,[],2);
  45. eegF = cat(2,eegF(:,gd+1:end),zeros(size(eegF,1),gd));
  46. eegData = eegF;
  47. %labelsFeat = {'sample','promZ','peakZ','peakRaw','promZbefore','promZafter',... %1..6
  48. % 'peakZbefore','peakZafter','minZbefore','minZafter',...%7..10
  49. % 'wDG','wBA','w50','tB','tA','tminB','tminA','acc','speed','max10_30before','max10_30after'}; %11..21
  50. %get features
  51. s = feat(:,1); %sample
  52. wDG = feat(:,11); %width
  53. dB = feat(:,3) - feat(:,9); %distance to min before
  54. dA = feat(:,3) - feat(:,10); %distance to min before
  55. dB = log(dB); %log (gamma)
  56. dA = log(dA); %log (gamma)
  57. mx = mean(dB);
  58. sx = std(dB);
  59. dB = (dB-mx)/sx; %zscore
  60. dA = (dA-mx)/sx;
  61. %criteria for DS
  62. k = dB > 0.75 & dA > 0.75 & wDG > 5 & wDG < 25;
  63. %select samples
  64. sk = s(k);
  65. resultsCSD = zeros(CSDres,length(sk));
  66. %get CSDs
  67. for sI = 1:length(sk)
  68. s = sk(sI);
  69. eeg = eegData(:,s-winLen:s+winLen);
  70. if methodSpline == 0
  71. %compute CSD - standard method
  72. %adding vaknin electrodes not to loose first and last channel
  73. %duplicate first and last channel
  74. eeg = cat(1,eeg(1,:),eeg,eeg(end,:));
  75. eeg = eeg + eeg;
  76. Nch = size(eeg,1);
  77. CSD = -ex_cond*D1(Nch,h)*eeeegAvergX;
  78. %filter iCSD
  79. b0 = 0.54; %center
  80. b1 = 0.23; %neighbor
  81. [n1,n2]=size(CSD);
  82. CSD_add(1,:) = zeros(1,n2); %add top and buttom row with zeros
  83. CSD_add(n1+2,:)=zeros(1,n2);
  84. CSD_add(2:n1+1,:)=CSD; %CSD_add has n1+2 rows
  85. CSD = S_general(n1+2,b0,b1)*CSD_add; % CSD has n1 row
  86. else
  87. % compute spline iCSD:
  88. Fcs = F_cubic_spline(el_pos,diam,ex_cond,top_cond);
  89. [zs,CSD_cs] = make_cubic_splines(el_pos,eeg,Fcs);
  90. if gauss_sigma~=0 %filter iCSD
  91. [~,CSD_cs]=gaussian_filtering(zs,CSD_cs,gauss_sigma,filter_range);
  92. end
  93. CSD = CSD_cs;
  94. end
  95. CSDp = CSD(:,winLen+1);
  96. resultsCSD(:,sI) = CSDp;
  97. end
  98. %plot results
  99. imagesc(resultsCSD,[-30000 30000])
  100. colormap(jet)
  101. text(5000,100,'<- outer mol.layer of superior DG blade (DSL)')
  102. text(5000,119,'<- middle mol.layer of superior DG blade (DSM)')
  103. text(5000,148,'<- hilus')
  104. text(5000,175,'<- middle mol.layer of inferior DG blade (DSM)')
  105. text(5000,192,'<- outer mol.layer of inferior DG blade (DSL)')
  106. save([drOUT fnEEG],'resultsCSD','sk');
  107. xlabel('Putative DS events');
  108. ylabel('Depth')