Commit 50e0ee12 authored by Jesse Heckman's avatar Jesse Heckman
Browse files

Initial commit

parents
File added
% PB_CALIBRATERAW
%
% This script semi-automates your .... analyses.
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Locate Dir
% clear all hidden;
% close all;
cfn = 0;
cdir = '/Users/jjheckman/Documents/Data/PhD/';
path = pb_getdir('dir',cdir);
if ~isempty(path); cd(path); end
%% horziontal, vertical, and frontal channel
cfn=cfn+1;figure(cfn);clf;
hor = []; ver = []; fron = [];
for i = 1:24
str = ['JJH-0001-18-04-04-0000-' sprintf('%04d',i) '.sphere'];
load(str, '-mat');
subplot(131)
hold on; axis([0 25 -10 10])
%plot(data.raw(:,1))
hor(i) = mean(data.raw(:,1));
cla; hh = plot(hor,'*-');
subplot(132)
hold on; axis([0 25 -10 10])
%plot(data.raw(:,2))
ver(i) = mean(data.raw(:,2));
cla; hv = plot(ver,'*-');
subplot(133)
hold on; axis([0 25 -10 10])
%plot(data.raw(:,3))
fron(i) = mean(data.raw(:,3));
cla; hf = plot(fron,'*-');
pb_nicegraph;
end
col = pb_selectcolor(3,2);
for j = 1:3
subplot(1,3,j)
h = findobj(gca,'Type','Line')
set(h,'Color',col(j,:))
end
cfn=cfn+1; figure(cfn);clf;
hold on; axis([0 25 -10 10])
plot(hor,'*-');
plot(ver,'*-');
plot(fron,'*-');
[~,lct] = findpeaks(abs(fron));
pb_vline(lct);
pb_nicegraph;
legend('Horizontal','Vertical','Frontal')
%% Load trails
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% PB_ANALYSISSACDET
%
% Goal:
% This script will guide you semi-automated through the process of
% selecting and loading the data.
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Select your Data folder
cd('/Users/jjheckman/Documents/Data/PhD'); % default data directory
cdir = uigetdir(); if cdir ~= 0; cd(cdir); end
%% Set variables
prompt = {
'Enter experimenter initials (XX): ', ...
'Enter year (YY): ', ...
'Enter month (MM): ', ...
'Enter day (DD): ', ...
'Particpant (000n): '};
formatOut = 'yy'; YYd = datestr(now,formatOut);
formatOut = 'mm'; MMd = datestr(now,formatOut);
formatOut = 'dd'; DDd = datestr(now,formatOut);
defAns = {'JJH',YYd,MMd,DDd,'000'};
title = 'Experiment selection';
numlines = 1;
answ = inputdlg(prompt,title,numlines,defAns);
s.XX = answ{1};
s.YY = answ{2};
s.MM = answ{3};
s.DD = answ{4};
s.PN = answ{5};
clear answ DDd defAns formatOut MMd numlines prompt title YYd;
fname = strcat(s.XX,'-',s.PN,'-',s.YY,'-',s.MM,'-',s.DD);
fn.s2hd = {
strcat(fname,'-0000.sphere'), ...
strcat(fname,'-0001.sphere')};
fn.cal = strcat(fname,'-0000.csv');
%% create data files
spheretrial2complete(); % creates 2 .sphere files: calibration "0000" block, and data "000n" block
% 1. Set trial directory as the 'Current Folder'
% 2. run spheretrial2complete();
sphere2hoopdat(fn.s2hd{1}); % calibration (*-0000-*.sphere) and data (*-000n-*.sphere) -> .dat
sphere2hoopdat(fn.s2hd{2});
sphere2hoopcsv(fn.s2hd{1}); % 2 calibration and data -> .csv
sphere2hoopcsv(fn.s2hd{2});
pa_calibrate() % calibrates "0000.csv" data: SELECT FILES MANUALLY
% 1. run neural network
% 2. save
% 3. calibrate
% output: *.hv
%% Fine tune saccades
pa_sacdet(strcat(fname,'-0001.hv')); % input: *.hv output:*.hv
%% Load variables
pa_sac2mat(); % MANUALLY select! input: *.hv / output: *.mat
load(strcat(fname,'-0001.mat')) % load 'XX-0001-YY-MM-DD-000n.mat --> create: Sac, Stim
clear fn fname s;
S = pb_stim2MSstim(Stim);
[M] = pa_supersac(Sac,Stim);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% PB_ANALYSISSACLOC
%
% This script semi-automates your saccade localization analyses.
% PBToolbox (2017): JJH: j.heckman@donders.ru.nl
%% Load data
% clear all hidden;
% close all;
cfn = 0;
cdir = '/Users/jjheckman/Documents/Data/PhD/';
[fpath] = pb_getfile('dir',cdir,'ext','*.mat');
if ~isempty(fpath); load(fpath); end
%% Convert MSI Stim
S = pb_stim2MSstim(Stim); % convert 'Stim' to contain multisensory stimuli
%% Extract modality-specific supersac data
V = pa_supersac(Sac, S,1,0); % visual
A = pa_supersac(Sac, S,2,0); % auditory
B = pa_supersac(Sac,S,3,0); % bimodal
M = [V;A;B]; % all
%% Evaluate stimulus duration
ss = M(M(:,30)==1,:); % 1 ms
sm = M(M(:,30)==3,:); % 3 ms
lm = M(M(:,30)==10,:); % 10 ms
ll = M(M(:,30)==30,:); % 30 ms
cfn=cfn+1; figure(cfn);
% Azimuth
y = ss(:,8); x = ss(:,23);
subplot(2,4,1); pb_regplot(x,y);
title('Azimuth accuracy for 1ms');
ylabel('Saccade Offset (\alpha degrees)');
xlabel('Target (\alpha degrees)');
pb_dline; axis([-100 100 -100 100]);
y = sm(:,8); x = sm(:,23);
subplot(2,4,2); pb_regplot(x,y);
title('Azimuth accuracy for 3ms');
xlabel('Target (\alpha degrees)');
pb_dline; axis([-100 100 -100 100]);
y = lm(:,8); x = lm(:,23);
subplot(2,4,3); pb_regplot(x,y);
title('Azimuth accuracy for 10ms');
xlabel('Target (\alpha degrees)');
pb_dline; axis([-100 100 -100 100]);
y = ll(:,8); x = ll(:,23);
subplot(2,4,4); [~,~,~] = pb_regplot(x,y);
title('Azimuth accuracy for 30ms');
xlabel('Target (\alpha degrees)');
pb_dline; axis([-100 100 -100 100]);
% Elevation
y = ss(:,9); x = ss(:,24);
subplot(2,4,5); pb_regplot(x,y);
title('Elevation accuracy for 1ms');
ylabel('Saccade Offset (\epsilon degrees)');
xlabel('Target (\epsilon degrees)');
pb_dline; axis([-100 100 -100 100]);
y = sm(:,9); x = sm(:,24);
subplot(2,4,6); pb_regplot(x,y);
title('Elevation accuracy for 3ms');
xlabel('Target (\epsilon degrees)');
pb_dline; axis([-100 100 -100 100]);
y = lm(:,9); x = lm(:,24);
subplot(2,4,7); pb_regplot(x,y);
title('Elevation accuracy for 10ms');
xlabel('Target (\epsilon degrees)');
pb_dline; axis([-100 100 -100 100]);
y = ll(:,9); x = ll(:,24);
subplot(2,4,8); pb_regplot(x,y);
title('Elevation accuracy for 30ms');
xlabel('Target (\epsilon degrees)');
pb_dline; axis([-100 100 -100 100]);
pb_nicegraph;
%% Plot saccades:
udur = unique(round(M(:,30)));
length(udur)
cfn=cfn+1; figure(cfn); clf;
for i = 1:length(udur)
subplot(2,3,i)
hold on;
sel = M(:,30) == udur(i) & M(:,2) == 2;
pb_regplot(M(sel,24),M(sel,9));
axis([-60 60 -60 60]);
pb_dline;
end
pb_nicegraph;
%% Saccade kinematics: 'Main Sequence'
% Select data
sel = M(:,16) <= 900;
M = M(sel,:);
Dur = M(:,14); PkV = M(:,16); Amp = M(:,12);
cfn=cfn+1;figure(cfn); clf;
% Duration vs amplitude
subplot(1,2,1);
plot(Amp,Dur,'o');
xlabel('Amplitude'); ylabel('Duration');
% Pk velocity vs amplitude
subplot(1,2,2);
plot(Amp,PkV,'o');
xlabel('Amplitude'); ylabel('Pk Velocity');
pb_nicegraph;
%% Probit plot
OnM = M(:,3)./6.1035-200; OffM = M(:,4)/6.1035-200;
OnA = A(:,3)./6.1035-200; OffA = A(:,4)/6.1035-200;
OnV = V(:,3)./6.1035-200; OffV = V(:,4)/6.1035-200;
OnB = B(:,3)./6.1035-200; OffB = B(:,4)/6.1035-200;
rtM = OnM+M(:,17);
rtA = OnA+A(:,17);
rtV = OnV+V(:,17);
rtB = OnB+B(:,17);
cfn=cfn+1; figure(cfn); clf;
subplot(221); hold on;
[~,stats] = pb_probit(rtV,'disp','true'); title('Visual ordinate');
subplot(222); hold on;
pb_probit(rtA); title('Auditory ordinate');
subplot(223); hold on;
pb_probit(rtB); title('Bimodal ordinate');
subplot(224); hold on;
pb_probit(rtM); title('Combined ordinate');
pb_nicegraph;
% Set different colors
col = pb_selectcolor(4,2);
for indA = 1:4
subplot(2,2,indA);
h = findobj(gca,'Type','Line');
set(h,'Color', col(indA,:));
end
%% PROBIT SEL
cfn=cfn+1; figure(cfn); clf;
subplot(131); title('Auditory ordinate');
hold on;
gs = 45;
% auditory
A_uR = unique(round(A(:,25)./gs).*gs)
num2str(A_uR)
for i=1:length(A_uR)
sel = round(A(:,25)/gs)*gs == A_uR(i);
OnA = A(:,3)./6.1035-200;
rtA = OnA;%+A(:,17);
rtA = rtA(sel);
pb_probit(rtA);
end
% visual
V_uR = unique(round(V(:,25)/gs)*gs);
subplot(132); title('Visual Oridnate');
hold on;
for j=1:length(V_uR)
sel = round(V(:,25)/gs)*gs == V_uR(j);
OnV = V(:,3)./6.1035-200;
rtV = OnV;%+V(:,17);
rtV = rtV(sel);
pb_probit(rtV);
end
legend(num2str(V_uR))
% bimodal
B_uR = unique(round(B(:,25)/gs)*gs);
subplot(133); title('Bimodal Oridnate');
hold on;
for k=1:length(B_uR)
sel = round(B(:,25)/gs)*gs == B_uR(k);
OnB = B(:,3)./6.1035-200;
rtB = OnB;%+B(:,17);
rtB = rtB(sel);
pb_probit(rtB);
end
legend(num2str(B_uR))
pb_nicegraph
%%
cfn=cfn+1; figure(cfn); clf;
hold on;
for i=1:6
subplot(6,3,i);
load(['snd' num2str(i*100)])
samples = length(snd);
t = 0:1:samples-1;
t = t./soundFs*1000;
plot(t,snd)
hold on;
syms x
pulse = heaviside(x)-heaviside(x-(samples-1)/soundFs*1000);
fplot(5*pulse);
h = findobj(gca,'Type','FunctionLine');
col=pb_selectcolor(2,2);
set(h,'Color',col(1,:),...
'LineWidth',2);
axis([-10 90 -10 10])
end
pb_nicegraph
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
\f0\fs24 \cf0 Steps to start working with the Programmeer Beer Toolbox:\
\
1) Store \'91PBToolbox\'92 in the directory of your choice.\
2) Open Matlab, navigate to directory, select add folder an subfolders to path.\
3) Type in command window: \'91pb_initializeToolbox\'92\
\
\
(c) Jesse J. Heckman, j.heckman@donders.ru.nl\
\
}
\ No newline at end of file
function [pb_name]()
% [PB_NAME]()
%
% Creates a template function for PBToolbox.
%
% [PB_NAME]() ...
%
% See also ...
% PBToolbox ([YEAR]): JJH: j.heckman@donders.ru.nl
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman ([YEAR]) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% [PB_NAME]
%
% This script semi-automates your .... analyses.
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%%
%%
%%
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\ No newline at end of file
File added
function bool = pb_and(logicArray)
% PB_AND()
%
% Iterates 'and'-logical operation on all elements of input argument.
%
% PB_AND(LOGIC) returns true when all elements are true, if any elements
% is false it returns false. If no input was provided, it returns false.
%
% See also PB_OR
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if nargin <1
bool = false;
return
end
logicArray = logicArray(:);
bool = logicArray(1);
for i=1:length(logicArray)-1
logicArray = logicArray(2:end);
bool = and(bool,logicArray(1));
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function chanDat = pb_createchanDat(channel,cfg)
% PB_NEWTARGET(CHANNEL,CHANDAT)
%
% Choose new X,Y coordinates for 2-stimuli paradigms.
%
% PB_NEWTARGET(CHANNEL,CHANDAT) generates new target coordinates for
% secundary targets, and selects new target based on multiplexers.
%
% See also GENEXP_LOC, GENEXP_DDS
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
chanDat = cfg.lookup(ismember(cfg.lookup(:,1),channel),:);
chanDat(:,7) = (chanDat(:,2)-1)*4+chanDat(:,3); % individual mplx (not RP2's!)
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [M] = pb_mergesacdat(varargin)
% M = PB_MERGESACDAT(M1,M2) or N = PB_MERGESACDAT(M1, M2, M3, M4...)