B_WaveformAnalysis.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. % extraction des data pour une waveform analysis
  2. clear all; clc;
  3. task_name={'DT5','FR5','FS5'};
  4. task_Dataset={'R_DT5','R_FR5','R_FS5'};
  5. figure;
  6. for task=1:length(task_Dataset)
  7. clear R selection X idx sizeplot color Celltype SesCelltype
  8. load(task_Dataset{task})
  9. WFlength=800; %total duration of the waevform 800microseconds
  10. bins=25;%bins=25microsecond
  11. time=(bins:bins:WFlength);
  12. runAnalysis=1;
  13. for i=1:size(R.WF,1)
  14. if sum(R.WF(i,:))==0
  15. R.WFanalysis(i,2)=0;
  16. R.WFanalysis(i,3)=0;
  17. else
  18. [maxValue, MaxIndex] = max(R.WF(i,:));
  19. [minValue, MinIndex] = min(R.WF(i,:));
  20. PeakValleyW=abs(time(MaxIndex)-time(MinIndex));
  21. PeakValleyM=abs(maxValue-minValue);
  22. R.WFanalysis(i,2)=PeakValleyM;
  23. idx = find(diff(R.WF(i,:) >= minValue/2));
  24. x2 = time(idx) + (minValue/2 - R.WF(i,idx)) .* (time(idx+1) - time(idx)) ./ (R.WF(i,idx+1) - R.WF(i,idx));
  25. if length(x2)==1
  26. R.WFanalysis(i,3)=NaN;
  27. else
  28. ValleyFWHM=x2(2)-x2(1);
  29. R.WFanalysis(i,3)=ValleyFWHM;
  30. end
  31. end
  32. end
  33. selection=R.WFanalysis(:,2)~=0;
  34. X=R.WFanalysis(selection,:);
  35. idx(1:sum(selection),1)=1;
  36. idx(X(:,1)>20,1)=2; % threshold 20Hz to separate MSN from FSI
  37. idx(idx(:,1)==2 & X(:,3)>150,1)=0;
  38. idx(idx(:,1)==1 & X(:,3)>450,1)=3;
  39. idx(X(:,1)>5 & idx(:,1)==3,1)=0;
  40. idx(X(:,1)<20 & X(:,1)>12.5 & idx(:,1)==1,1)=0; % intermediate frequencies = not classified
  41. idx(X(:,3)<450 & X(:,3)>400 & idx(:,1)==1,1)=0; % intermediate frequencies = not classified
  42. nbExcludedN=sum(idx(:,1)==0);
  43. for Y=1:size(idx,1)
  44. if idx(Y,1)==1
  45. color(Y,:)=[255/255 0/255 0/255];%MSN
  46. sizeplot(Y,1)=50;
  47. elseif idx(Y,1)==2
  48. color(Y,:)=[0 255/255 0/255];%FSI
  49. sizeplot(Y,1)=50;
  50. elseif idx(Y,1)==3
  51. color(Y,:)=[0/255 0/255 255/255]; %TAN
  52. sizeplot(Y,1)=50;
  53. elseif idx(Y,1)==0
  54. color(Y,:)=[0/255 0/255 0/255];%unclassified
  55. sizeplot(Y,1)=5;
  56. end
  57. end
  58. subplot(3,4,[task 4+task 8+task])
  59. scatter(X(:,1),X(:,3),sizeplot,color)
  60. hold on
  61. title(task_name{task})
  62. xlabel('Firing rate') % x-axis label
  63. ylabel('half-width')% y-axis label
  64. axis([0 50,0 600])
  65. hold off
  66. Celltype(1:length(selection),1)=R.SESSION;
  67. Celltype(1:length(selection),2)=0;
  68. Celltype(selection,2)=idx(:,1);
  69. for i=1:max(Celltype(:,1))
  70. firstUnitID=find(Celltype(:,1)==i,1,'first');
  71. LastUnitID=find(Celltype(:,1)==i,1,'last');
  72. SesCelltype(i).Celltype=Celltype(firstUnitID:LastUnitID,2);
  73. end
  74. save([task_Dataset{task},'.mat'],'R','Celltype','SesCelltype')
  75. end
  76. %% examples of waveforms
  77. subplot(3,4,4)
  78. TAN_id=find(Celltype(:,2)==3);
  79. plot(time,R.WF(TAN_id(2),:))
  80. axis([0 800 -0.15 0.15 ])
  81. subplot(3,4,8)
  82. MSN_id=find(Celltype(:,2)==1);
  83. plot(time,R.WF(MSN_id(2),:))
  84. axis([0 800 -0.4 0.4])
  85. subplot(3,4,12)
  86. FSI_id=find(Celltype(:,2)==2);
  87. plot(time,R.WF(FSI_id(2),:))
  88. axis([0 800 -0.2 0.1])