|
@@ -0,0 +1,187 @@
|
|
|
+function [uniformSpot_output]=BC_uniformSpot(loadData,filename,filename2,spotDuration,grayDuration,spotVersion,pathStimSignal)
|
|
|
+%[uniformSpot_output]=BC_uniformSpot(loadData,filename,filename2,spotDuration,grayDuration,spotVersion,pathStimSignal)
|
|
|
+%this function shows the example analysis for the uniform spot stimulus with
|
|
|
+%different spot sizes for both preferred and non-preferred contrasts. It is
|
|
|
+%used for cells that were recorded with stimulus version 1 and 2.
|
|
|
+%Inputs:
|
|
|
+% loadData = the folder path of the patterned spot files
|
|
|
+% filename = the filename of the BC of interest for black
|
|
|
+% contrast
|
|
|
+% filename2 = the filename of the BC of interest for white
|
|
|
+% contrast
|
|
|
+% spotDuration = duration of spot in ms, found in
|
|
|
+% the excel file LogInfo_UniformSpot.xlsx
|
|
|
+% grayDuration = duration of gray screen in ms, found in
|
|
|
+% the excel file LogInfo_UniformSpot.xlsx
|
|
|
+% spotVersion = spot version used, found in
|
|
|
+% the excel file LogInfo_UniformSpot.xlsx
|
|
|
+% pathStimSignal = folder path to load the sequence of spot
|
|
|
+% sizes shown
|
|
|
+%
|
|
|
+%Outpus: uniformSpot_output = structure containing the output
|
|
|
+% average membrane potential per spot size of the uniform
|
|
|
+% spot for the black and white spot
|
|
|
+%
|
|
|
+% code by HS last modiefied March 2021
|
|
|
+
|
|
|
+%% Constants
|
|
|
+mircoMeter_proPixel=2.5; %one monitor pixel is 2.5 micrometers
|
|
|
+
|
|
|
+%-------------------------------------------------------------------------------
|
|
|
+%% 1. load the spot sizes
|
|
|
+if spotVersion ==1
|
|
|
+ npatterns=13; %13 spot sizes were shown
|
|
|
+ micro_meter=[2,4,5,6,8,10,16,24,32,50,100,200,240]'*2*mircoMeter_proPixel; %spot diameter size in micro meters
|
|
|
+elseif spotVersion==2
|
|
|
+ npatterns=11; %11 spot sizes were shown
|
|
|
+ micro_meter=[2,4,6,8,10,16,24,32,50,100,200]'*2*mircoMeter_proPixel; %spot diameter size in micro meters
|
|
|
+end
|
|
|
+%for plotting add the mircometer label
|
|
|
+micrometer_label=repmat(' \mum',size(micro_meter,1),1);
|
|
|
+micro_meter_withLabel=strcat (num2str(micro_meter),micrometer_label);
|
|
|
+
|
|
|
+load(pathStimSignal); %load the order of the presentation of the diameter sizes. See Documentation_Data_BCRecordings. It contains values from 0-12 and the numbers refer to the spot size presented, where 0=smallest spot size and 12=largest spot size. It contains the pulses for a 15 minute recording
|
|
|
+
|
|
|
+%------------------------------------------------------------------------------------------
|
|
|
+%% 2. extract the membrane potential data for each spot size of the black spot and build the average
|
|
|
+data=load([loadData,filename]); %load the file for the black spot
|
|
|
+%only get the frames where the gray screen was shown (that you have one
|
|
|
+%frame per trial)
|
|
|
+ttls_ms_forCond=data.ttls_ms(1:2:end);
|
|
|
+%correct stimulus signal for the amount of ttls pulses you showed the
|
|
|
+%spot -> usually less than 15minutes
|
|
|
+stimulus_corr=stimulus(1:size(ttls_ms_forCond,1),:);
|
|
|
+
|
|
|
+%extract the membrane potential per spot
|
|
|
+membPot_perTrialBlackSpot=cell(1,npatterns);
|
|
|
+for j=0:npatterns-1 %loop over spot sizes
|
|
|
+ spot_cond=find(stimulus_corr==j);%get all the spots with same size
|
|
|
+ ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
|
|
|
+ if ~isempty(ttls_forCond)
|
|
|
+ %get the membrane potenial for this ttls signal (start gray screen) and go until
|
|
|
+ %the next spot (grayScreen 1000ms+500msSpot+1000gray)
|
|
|
+ for jj=1:length(ttls_forCond)
|
|
|
+ if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data, when you end the recording it can happen that you end it during a trial -> those trials you dont consider here
|
|
|
+ membPot_perTrialBlackSpot{j+1}(jj,:)=data.membPot(ttls_forCond(jj): ...
|
|
|
+ (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ clear spot_cond ttls_forCond
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+% baseline on trial by trial bases -> substract from the time series of each trial
|
|
|
+% the mean value of the 200 ms before the spot arrives
|
|
|
+membPot_trBasMeanBlackSpot=cell(1,npatterns);
|
|
|
+basValue=-200;%amount of baseline ->200ms
|
|
|
+for ww=1:length(membPot_perTrialBlackSpot)%nbr of spot sizes
|
|
|
+ val_before=membPot_perTrialBlackSpot{ww}(:,grayDuration+basValue:grayDuration-1);
|
|
|
+ byTrBas_perSpot=(mean(val_before,2));
|
|
|
+ trBas_repMAt=repmat(byTrBas_perSpot,1, ...
|
|
|
+ size(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
|
|
|
+ membPot_trBasMeanBlackSpot{ww}=mean(membPot_perTrialBlackSpot{ww}(:,grayDuration+1:end)- ...
|
|
|
+ trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
|
|
|
+ clear trBas_perSpotrepMAt
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+%------------------------------------------------------------------------------------------
|
|
|
+%% 3. extract the membrane potential data for each spot size of the white spot and build the average
|
|
|
+data=load([loadData,filename2]); %load the file for the white spot
|
|
|
+%only get the frames where the gray screen was shown (that you have one
|
|
|
+%frame per trial)
|
|
|
+ttls_ms_forCond=data.ttls_ms(1:2:end);
|
|
|
+%correct stimulus signal for the amount of ttls pulses you showed the
|
|
|
+%spot -> usually less than 15minutes
|
|
|
+stimulus_corr=stimulus(1:size(ttls_ms_forCond,1),:);
|
|
|
+clear stimulus
|
|
|
+
|
|
|
+%extract the membrane potential per spot
|
|
|
+membPot_perTrialWhiteSpot=cell(1,npatterns);
|
|
|
+for j=0:npatterns-1 %loop over spot sizes
|
|
|
+ spot_cond=find(stimulus_corr==j);%get all the spots with same size
|
|
|
+ ttls_forCond=ttls_ms_forCond(spot_cond);%get the ttls signals for this circle size
|
|
|
+ if ~isempty(ttls_forCond)
|
|
|
+ %get the membrane potenial for this ttls signal (start gray screen) and go until
|
|
|
+ %the next spot (grayScreen 1000ms+500msSpot+1000gray)
|
|
|
+ for jj=1:length(ttls_forCond)
|
|
|
+ if length(data.membPot)>=(ttls_forCond(jj)+spotDuration-1+grayDuration*2)==1 %only if you have enought data, when you end the recording it can happen that you end it during a trial -> those trials you dont consider here
|
|
|
+ membPot_perTrialWhiteSpot{j+1}(jj,:)=data.membPot(ttls_forCond(jj): ...
|
|
|
+ (ttls_forCond(jj)+spotDuration-1+2*grayDuration)); %duration-1 -> because the next trial would start there
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ clear spot_cond ttls_forCond
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+% baseline on trial by trial bases -> substract from the time series of each trial
|
|
|
+% the mean value of the 200 ms before the spot arrives
|
|
|
+membPot_trBasMeanWhiteSpot=cell(1,npatterns);
|
|
|
+basValue=-200;%amount of baseline ->200ms
|
|
|
+for ww=1:length(membPot_perTrialWhiteSpot)%nbr of spot sizes
|
|
|
+ val_before=membPot_perTrialWhiteSpot{ww}(:,grayDuration+basValue:grayDuration-1);
|
|
|
+ byTrBas_perSpot=(mean(val_before,2));
|
|
|
+ trBas_repMAt=repmat(byTrBas_perSpot,1, ...
|
|
|
+ size(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end),2)); %directly take the signal after gray screen
|
|
|
+ membPot_trBasMeanWhiteSpot{ww}=mean(membPot_perTrialWhiteSpot{ww}(:,grayDuration+1:end)- ...
|
|
|
+ trBas_repMAt,1);%mean for each trial, directly take the signal after gray screen
|
|
|
+ clear trBas_perSpotrepMAt
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+%------------------------------------------------------------------------------------------
|
|
|
+%% 4. Plot the data
|
|
|
+figure;
|
|
|
+subplot(1,2,1)
|
|
|
+%black spot with different sizes If you use earlier MATLAB versions you
|
|
|
+%might have to choose for each spot size a different color
|
|
|
+%50um
|
|
|
+micro50=find(micro_meter==50);
|
|
|
+plot(membPot_trBasMeanBlackSpot{micro50},'linewidth',3)
|
|
|
+hold on
|
|
|
+%80um
|
|
|
+micro80=find(micro_meter==80);
|
|
|
+plot(membPot_trBasMeanBlackSpot{micro80},'linewidth',3)
|
|
|
+%120um
|
|
|
+micro120=find(micro_meter==120);
|
|
|
+plot(membPot_trBasMeanBlackSpot{micro120},'linewidth',3)
|
|
|
+%legend
|
|
|
+legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
|
|
|
+title('black spot')
|
|
|
+xlabel('time(ms)')
|
|
|
+ylabel('voltage(mV)')
|
|
|
+YLIM=ylim;
|
|
|
+
|
|
|
+subplot(1,2,2)
|
|
|
+%white spot with different sizes
|
|
|
+%50um
|
|
|
+plot(membPot_trBasMeanWhiteSpot{micro50},'linewidth',3)
|
|
|
+hold on
|
|
|
+%80um
|
|
|
+plot(membPot_trBasMeanWhiteSpot{micro80},'linewidth',3)
|
|
|
+%120um
|
|
|
+plot(membPot_trBasMeanWhiteSpot{micro120},'linewidth',3)
|
|
|
+%legend
|
|
|
+legend({micro_meter_withLabel([micro50,micro80,micro120],:)})
|
|
|
+title('white spot')
|
|
|
+xlabel('time(ms)')
|
|
|
+ylabel('voltage(mV)')
|
|
|
+YLIM2=ylim;
|
|
|
+
|
|
|
+%find max of the two ylims and adapt ylims to compare the two plots so that
|
|
|
+%they have the same ylims
|
|
|
+minY=min([YLIM,YLIM2])-0.5;
|
|
|
+maxY=max([YLIM,YLIM2])+0.5;
|
|
|
+subplot(1,2,1)
|
|
|
+ylim([minY maxY])
|
|
|
+subplot(1,2,2)
|
|
|
+ylim([minY maxY])
|
|
|
+
|
|
|
+%-------------------------------------------------------------------------------
|
|
|
+%% 5. add variables into the output
|
|
|
+uniformSpot_output.membPot_trBasMeanBlackSpot=membPot_trBasMeanBlackSpot;
|
|
|
+uniformSpot_output.membPot_trBasMeanWhiteSpot=membPot_trBasMeanWhiteSpot;
|
|
|
+uniformSpot_output.micro_meter=micro_meter;
|
|
|
+end
|