BC_patternedSpot.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. function [patternedSpot_output]=BC_patternedSpot(loadData,filename,Hz,inputFrames)
  2. %[patternedSpot_output]=BC_patternedSpot(loadData,filename,Hz,inputFrames)
  3. %this function shows the analysis for the patterned spot stimulus. The
  4. %baseline average response per patterned spot stimulus is computed.
  5. %Inputs:
  6. % loadData = the folder path of the patterned spot files
  7. % filename = the filename of the BC of interest
  8. % Hz = reversing frequency of the patterned spot
  9. % inputFrames = the starting and ending frame times of the
  10. % patterned spots from the excel file LogInfo_PatternedSpot.xlsx
  11. %
  12. %Outpus: patternedSpot_output = structure containing the output
  13. % average membrane potential per patterned spot and fourier output
  14. %
  15. % code by HS last modiefied March 2021
  16. %% Constants
  17. %starting and end frame for the split-spot
  18. start_halfSpot=inputFrames(1);
  19. end_halfSpot=inputFrames(2);
  20. %starting and end frame for the spot divided into 4 quarters
  21. start_quarterSpot=inputFrames(3);
  22. end_quarterSpot=inputFrames(4);
  23. %starting and end frame for the spot with 25micron subfields
  24. start_25microSpot=inputFrames(5);
  25. end_25microSpot=inputFrames(6);
  26. %start and end frame for the spots recorded with version 2 (see excel file)
  27. if length(inputFrames) > 6
  28. %for 10 micron subfields
  29. start_10microSpot=inputFrames(7); end_10microSpot=inputFrames(8);
  30. %for the uniform spot
  31. start_UniformSpot=inputFrames(9); end_UniformSpot=inputFrames(10);
  32. end
  33. %-------------------------------------------------------------------------------
  34. %% 1. load the patterned spot file
  35. data=load([loadData,filename]); %load the file
  36. %------------------------------------------------------------------------------------------
  37. %% 2. build average response to split spot
  38. indx=start_halfSpot; %you start with the splitspot
  39. basValue=200;%get baseline (200ms) before the stimulus.
  40. %The index in the excel file gives
  41. %the start of the 2 trial already, one trial is 1000ms, therefore you
  42. %have to go 1200ms before the index to get the 200ms beseline
  43. oneperiod=1000/Hz; %time in ms of one period of the stimulus
  44. %get the average baselined response to the split spot
  45. memPotAVG_splitSpot=getAVGResponse(data,basValue,oneperiod,indx);
  46. %------------------------------------------------------------------------------------------
  47. %% 3. build average response to quarter spot
  48. indx=start_quarterSpot; %you start with the spot
  49. %get the average baselined response to the quarter spot
  50. memPotAVG_quarterSpot=getAVGResponse(data,basValue,oneperiod,indx);
  51. %------------------------------------------------------------------------------------------
  52. %% 4. build average response to 25micron spot
  53. indx=start_25microSpot; %you start with the spot
  54. %get the average baselined response to the 25micron spot
  55. memPotAVG_25microSpot=getAVGResponse(data,basValue,oneperiod,indx);
  56. %------------------------------------------------------------------------------------------
  57. %% 5. only for stimulus version 2 build average for 10micron spot and uniform spot
  58. if length(inputFrames) > 6
  59. %------------------------------------------------------------------------------------------
  60. %% 5.1 build average response to 15micron spot
  61. indx=start_10microSpot; %you start with the spot
  62. %get the average baselined response to the 10micron spot
  63. memPotAVG_10microSpot=getAVGResponse(data,basValue,oneperiod,indx);
  64. %------------------------------------------------------------------------------------------
  65. %% 5.2 build average response to uniform spot
  66. indx=start_UniformSpot; %you start with the spot
  67. %get the average baselined response to the uniform spot
  68. memPotAVG_uniformSpot=getAVGResponse(data,basValue,oneperiod,indx);
  69. else
  70. %get the response to the uniform spot from the loaded file
  71. memPotAVG_uniformSpot=data.uniformTraceAVG;
  72. end
  73. %------------------------------------------------------------------------------------------
  74. %% 6. Plot the data
  75. figure;
  76. %uniform spot
  77. subplot(2,2,1)
  78. %get max and min to set same axis for all the patterned
  79. %spot
  80. YLIM=[min([memPotAVG_uniformSpot,memPotAVG_splitSpot,memPotAVG_quarterSpot,memPotAVG_25microSpot])-0.5,...
  81. max([memPotAVG_uniformSpot,memPotAVG_splitSpot,memPotAVG_quarterSpot,memPotAVG_25microSpot])+0.5];
  82. plot(memPotAVG_uniformSpot,'k','linewidth',3) %original membrane potential
  83. title('uniform spot')
  84. xlabel('time(ms)')
  85. ylabel('voltage (mV)')
  86. ylim(YLIM);
  87. %split spot
  88. subplot(2,2,2)
  89. plot(memPotAVG_splitSpot,'k','linewidth',3) %original membrane potential
  90. title('split spot')
  91. xlabel('time(ms)')
  92. ylabel('voltage (mV)')
  93. ylim(YLIM);
  94. %1/4 spot
  95. subplot(2,2,3)
  96. plot(memPotAVG_quarterSpot,'k','linewidth',3) %original membrane potential
  97. title('quarter spot')
  98. xlabel('time(ms)')
  99. ylabel('voltage (mV)')
  100. ylim(YLIM);
  101. %25micron subfield spot
  102. subplot(2,2,4)
  103. plot(memPotAVG_25microSpot,'k','linewidth',3) %original membrane potential
  104. title('25micron subfields spot')
  105. xlabel('time(ms)')
  106. ylabel('voltage (mV)')
  107. ylim(YLIM);
  108. %-------------------------------------------------------------------------------
  109. %% 5. add variables into the output
  110. patternedSpot_output.memPotAVG_uniformSpot=memPotAVG_uniformSpot;
  111. patternedSpot_output.memPotAVG_splitSpot=memPotAVG_splitSpot;
  112. patternedSpot_output.memPotAVG_quarterSpot=memPotAVG_quarterSpot;
  113. patternedSpot_output.memPotAVG_25microSpot=memPotAVG_25microSpot;
  114. if length(inputFrames) > 6
  115. patternedSpot_output.memPotAVG_10microSpot=memPotAVG_10microSpot;
  116. end
  117. end
  118. function membPotAVG_trBas=getAVGResponse(data,basValue,oneperiod,indx)
  119. memPot_basTemp=data.membPot(data.ttls_ms(indx)-oneperiod-basValue: ...
  120. data.ttls_ms(indx)-oneperiod-1); %baseline 200ms before
  121. for jj=1:3 %amount of black spot start per size ->only analyse 3!
  122. membPot_perTrial(jj,:)=data.membPot(data.ttls_ms(indx): ...
  123. data.ttls_ms(indx)+oneperiod-1); %duration 1000 ms for black and white together
  124. indx=indx+2;
  125. end
  126. memPotAVG= mean(membPot_perTrial);
  127. membPotAVG_trBas= memPotAVG-mean(memPot_basTemp);
  128. end