BC_uniformSpot3.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. function [uniformSpot_output]=BC_uniformSpot3(loadData,filename,spotDuration,grayDuration,inputFrames,pathStimSignal)
  2. %[uniformSpot_output]=BC_uniformSpot3(loadData,filename,spotDuration,grayDuration,contrast)
  3. %this function shows the example analysis for the uniform spot stimulus with
  4. %different spot sizes for stimulus version 3. Here the black and white spot
  5. %are recorded in the same file
  6. %Inputs:
  7. % loadData = the folder path of the patterned spot files
  8. % filename = the filename of the BC of interest
  9. % spotDuration = duration of spot in ms, found in
  10. % the excel file LogInfo_PatternedSpot.xlsx
  11. % grayDuration = duration of gray screen in ms, found in
  12. % the excel file LogInfo_PatternedSpot.xlsx
  13. % inputFrames = start and end frames of the different
  14. % contrast spots, found in the excel file
  15. % LogInfo_PatternedSpot.xlsx
  16. % pathStimSignal = folder path to load the sequence of spot
  17. % sizes shown
  18. %
  19. %
  20. %Outpus: uniformSpot_output = structure containing the output
  21. % average membrane potential per spot size of the uniform
  22. % spot for both black and white contrast.
  23. %
  24. % code by HS last modiefied March 2021
  25. %% Constants
  26. mircoMeter_proPixel=2.5; %one monitor pixel is 2.5 micrometers
  27. %-------------------------------------------------------------------------------
  28. %% 1. load the patterned spot file
  29. data=load([loadData,filename]); %load the file
  30. %-------------------------------------------------------------------------------
  31. %% 2. load the spot sizes
  32. %same as spot version 2
  33. npatterns=11; %11 spot sizes were shown
  34. micro_meter=[2, 6, 8, 10, 12, 16, 24, 32, 50, 100, 200 ]'*2*mircoMeter_proPixel;
  35. %for plotting add the mircometer label
  36. micrometer_label=repmat(' \mum',size(micro_meter,1),1);
  37. micro_meter_withLabel=strcat (num2str(micro_meter),micrometer_label);
  38. load(pathStimSignal); %load the order of the presentation of the diameter sizes. See Documentation_Data_BCRecordings. It contains values from 10-1000 and the numbers refer to the spot size in micrometers. The same order was used for black and white spots
  39. %------------------------------------------------------------------------------------------
  40. %% 3. extract the membrane potential data for the black spot, for each spot size and build the average
  41. %start of black spot
  42. start_blackSpot=inputFrames(1);
  43. %end of black spot
  44. end_blackSpot=inputFrames(2);
  45. %only get the frames where the gray screen was shown (that you have one
  46. %frame per trial)
  47. ttls_ms_forCond=data.ttls_ms(1:2:end_blackSpot);
  48. %extract the membrane potential per spot
  49. membPot_perTrialBlackSpot=cell(1,npatterns);
  50. for j=1:npatterns %loop over spot sizes
  51. spot_cond=find(stimulus==micro_meter(j));%get all the spots with same size
  52. ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
  53. if ~isempty(ttls_forCond)
  54. %get the membrane potenial for this ttls signal (start gray screen) and go until
  55. %the next spot (grayScreen 1000ms+500msSpot+1000gray)
  56. for jj=1:length(ttls_forCond)
  57. if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data
  58. membPot_perTrialBlackSpot{j}(jj,:)=data.membPot(ttls_forCond(jj): ...
  59. (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
  60. end
  61. end
  62. end
  63. clear spot_cond ttls_forCond
  64. end
  65. % baseline on trial by trial bases -> substract from the time series of each trial
  66. % the mean value of the 200 ms before the spot arrives
  67. membPot_trBasMeanBlackSpot=cell(1,npatterns);
  68. basValue=-200;%amount of baseline ->200ms
  69. for ww=1:length(membPot_perTrialBlackSpot)%nbr of spot sizes
  70. val_before=membPot_perTrialBlackSpot{ww}(:,grayDuration+basValue:grayDuration-1);
  71. byTrBas_perSpot=(mean(val_before,2));
  72. trBas_repMAt=repmat(byTrBas_perSpot,1, ...
  73. size(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
  74. membPot_trBasMeanBlackSpot{ww}=mean(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end)- ...
  75. trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
  76. clear trBas_perSpotrepMAt
  77. end
  78. %------------------------------------------------------------------------------------------
  79. %% 3. extract the membrane potential data for the white spot, for each spot size and build the average
  80. %start of black spot
  81. start_whiteSpot=inputFrames(3);
  82. %end of black spot
  83. end_whiteSpot=inputFrames(4);
  84. %only get the frames where the gray screen was shown (that you have one
  85. %frame per trial)
  86. ttls_ms_forCond=data.ttls_ms(start_whiteSpot:2:end_whiteSpot);
  87. %extract the membrane potential per spot
  88. membPot_perTrialWhiteSpot=cell(1,npatterns);
  89. for j=1:npatterns %loop over spot sizes
  90. spot_cond=find(stimulus==micro_meter(j));%get all the spots with same size
  91. ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
  92. if ~isempty(ttls_forCond)
  93. %get the membrane potenial for this ttls signal (start gray screen) and go until
  94. %the next spot (grayScreen 1000ms+500msSpot+1000gray)
  95. for jj=1:length(ttls_forCond)
  96. if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data
  97. membPot_perTrialWhiteSpot{j}(jj,:)=data.membPot(ttls_forCond(jj): ...
  98. (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
  99. end
  100. end
  101. end
  102. clear spot_cond ttls_forCond
  103. end
  104. % baseline on trial by trial bases -> substract from the time series of each trial
  105. % the mean value of the 200 ms before the spot arrives
  106. membPot_trBasMeanWhiteSpot=cell(1,npatterns);
  107. basValue=-200;%amount of baseline ->200ms
  108. for ww=1:length(membPot_perTrialWhiteSpot)%nbr of spot sizes
  109. val_before=membPot_perTrialWhiteSpot{ww}(:,grayDuration+basValue:grayDuration-1);
  110. byTrBas_perSpot=(mean(val_before,2));
  111. trBas_repMAt=repmat(byTrBas_perSpot,1, ...
  112. size(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
  113. membPot_trBasMeanWhiteSpot{ww}=mean(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end)- ...
  114. trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
  115. clear trBas_perSpotrepMAt
  116. end
  117. %------------------------------------------------------------------------------------------
  118. %% 4. Plot the data
  119. figure;
  120. %black spot
  121. subplot(1,2,1)
  122. %uniform spot, different sizes If you use earlier MATLAB versions you
  123. %might have to choose for each spot size a different color
  124. %50um
  125. micro50=find(micro_meter==50);
  126. plot(membPot_trBasMeanBlackSpot{micro50},'linewidth',3)
  127. hold on
  128. %80um
  129. micro80=find(micro_meter==80);
  130. plot(membPot_trBasMeanBlackSpot{micro80},'linewidth',3)
  131. %120um
  132. micro120=find(micro_meter==120);
  133. plot(membPot_trBasMeanBlackSpot{micro120},'linewidth',3)
  134. xlabel('time(ms)')
  135. ylabel('voltage(mV)')
  136. %legend
  137. legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
  138. title('black spot')
  139. YLIM=ylim;
  140. %white spot
  141. subplot(1,2,2)
  142. %uniform spot, different sizes
  143. %50um
  144. micro50=find(micro_meter==50);
  145. plot(membPot_trBasMeanWhiteSpot{micro50},'linewidth',3)
  146. hold on
  147. %80um
  148. micro80=find(micro_meter==80);
  149. plot(membPot_trBasMeanWhiteSpot{micro80},'linewidth',3)
  150. %120um
  151. micro120=find(micro_meter==120);
  152. plot(membPot_trBasMeanWhiteSpot{micro120},'linewidth',3)
  153. %legend
  154. legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
  155. title('white spot')
  156. xlabel('time(ms)')
  157. ylabel('voltage(mV)')
  158. YLIM2=ylim;
  159. %find max of the two ylims and adapt ylims to compare the two plots so that
  160. %they have the same ylims
  161. minY=min([YLIM,YLIM2])-0.5;
  162. maxY=max([YLIM,YLIM2])+0.5;
  163. subplot(1,2,1)
  164. ylim([minY maxY])
  165. subplot(1,2,2)
  166. ylim([minY maxY])
  167. %-------------------------------------------------------------------------------
  168. %% 5. add variables into the output
  169. uniformSpot_output.membPot_trBasMean=membPot_trBasMeanBlackSpot;
  170. uniformSpot_output.membPot_trBasMeanWhiteSpot=membPot_trBasMeanWhiteSpot;
  171. uniformSpot_output.micro_meter=micro_meter;
  172. end