Commit 64312c3c authored by mposthuma's avatar mposthuma
Browse files

Added Response plot script Azimuth + elevation Test exp. Made seperate sacdet...

Added Response plot script Azimuth + elevation Test exp. Made seperate sacdet script. Removed epoching and sacdet from test experiment (eye gaze target plots)
parent 7f6dba88
%% Initialize
% Clean everythimg
cfn = pb_clean('cd','U:\Documents\BIOLOGIE\STAGE\MATLAB\Data\test experiment'); % clean everything, and change directory
% load epoched data
l = dir('epoched_data_*.mat');
for iL = 1:length(l)
load(l(iL).name);
end
%pa_sac2mat to save sac to mat file
% load saccades
l = dir(['sacdet' filesep 'sacdet*.mat']);
load(['sacdet' filesep l(1).name]);
%% Extract data
% get epoched gaze data traces
azimuth = Data.epoch.AzGazeEpoched;
elevation = Data.epoch.ElGazeEpoched;
% Run over saccades
for iS = 1:length(Sac)
trial_idx = Sac(iS,1);
% Get timings
start_trial_idx = (trial_idx-1)*360+1;
stimOn_idx = start_trial_idx;
sacOn_idx = Sac(iS,3) + start_trial_idx-1;
sacOff_idx = Sac(iS,4) + start_trial_idx-1;
% Super sac
SS(iS,1:4) = Sac(iS,1:4); % trial / saccade nr / sacc on sample / sac off sample
SS(iS,5) = 1/120 * 1000 * Sac(iS,3); % RT
SS(iS,6) = 1/120 * 1000 * (Sac(iS,4)-Sac(iS,3)); % Duration
SS(iS,7) = azimuth(sacOn_idx); % Azimuth onset position
SS(iS,8) = elevation(sacOn_idx); % Elevation onset position
SS(iS,9) = azimuth(sacOff_idx); % Azimuth offset position
SS(iS,10) = elevation(sacOff_idx); % Elevation offset position
SS(iS,11) = SS(iS,9) - SS(iS,7); % Azimuth Saccade amplitude
SS(iS,12) = SS(iS,10) - SS(iS,8); % Elevation Saccade amplitude
SS(iS,13) = Data.stimuli.azimuth(SS(iS,1)); % Target Azimuth
SS(iS,14) = Data.stimuli.elevation(SS(iS,1)); % Target Elevation
end
%%
% criteria
sel_first = SS(:,2)==1; % only first saccade
sel_timing = SS(:,5)>80 & SS(:,5)<400; % between 80 - 400 ms
sel_SS = sel_first & sel_timing; % combine all selections
nSS = SS(sel_SS,:);
n_sacc = sum(sel_SS);
c_title = {'Azimuth','Elevation'};
col = pb_selectcolor(2,2);
cfn = pb_newfig(cfn);
for iS = 1:2
% get data
target = nSS(:,12+iS);
resp = nSS(:,10+iS);
% graph
subplot(1,2,iS);
hold on;
axis square;
title(c_title{iS});
h(iS) = plot(target,resp,'o');
hr(iS) = pb_regplot(target,resp,'data',false);
xlabel('Target ($^{\circ}$)');
ylabel('Response ($^{\circ}$)')
xlim([-50 50]);
ylim([-50 50]);
pb_dline;
end
pb_nicegraph;
% color
for iH = 1:length(h)
h(iH).Color = col(iH,:);
hr(iH).Color = col(col(iH,:));
end
cfn = pb_clean('cd','C:\Users\marc_\OneDrive\Documents\Studie\STAGE\MATLAB Code\Data\Recordings\test experiment');
%% Raw data conversion + Save preprocessed Data
cfn = pb_clean('cd','U:\Documents\BIOLOGIE\STAGE\MATLAB\Data\test experiment');
l = dir('converted_data*.mat');
if isempty(l)
......@@ -78,7 +79,7 @@ for i = 1:3:10
i
end
%%
%% Epoch data
fs = 120;
duration = 3;
......@@ -121,8 +122,8 @@ for iB = 1:length(Data.timestamps)
% Select stimuli indices
nstim = length(Data.stimuli(iB).azimuth);
ntriggers = length(Data.timestamps(iB).stimuli);
ind = 1;
ext = 2;
ind = 3;
ext = 4;
for iS = 1:nstim
% epoch for stimuli
......@@ -153,55 +154,3 @@ end
fn = strrep('preprocessed_data_JJH-0001-21-04-15-0001.mat','preprocessed','epoched');
save(fn,'Data');
%%
if ~exist('sacdet','dir')
mkdir('sacdet')
end
cfn = pb_clean('cd','C:\Users\marc_\OneDrive\Documents\Studie\STAGE\MATLAB Code\Data\Recordings\test experiment');
path = pb_getdir('cdir',cd);
cd(path)
% Load data
l = dir('epoched*.mat');
if isempty(l); return; end
fn = l(1).name;
load(fn);
% Switch to sacdet folder
path = [path filesep 'sacdet'];
cd(path)
%% Run sacdet over epoched data
% Read converted data file, preprocess all blocks, and store data
l = dir('*.sac');
if ~isempty(l); return; end
%% Make hv & csv and run sacdet
Dlen = length(Data.epoch);
fs = 120;
duration = 3;
samples = duration * fs;
for iB = 1:Dlen
% Saving calibrated data
fname = fcheckext(['sacdet_' fn(14:end-5) '_block_' num2str(iB) '_azel'] ,'.hv');
fid = fopen([path filesep fname],'w','l');
AZEL = [Data.epoch(iB).AzGazeEpoched; Data.epoch(iB).ElGazeEpoched];
fwrite(fid,AZEL,'float');
fclose(fid);
fn_csv = [path filesep fname];
VC2csv(fn_csv,fs,samples,1:length(Data.epoch(iB).AzGazeEpoched)/samples);
if ~isfile(fn_csv(1:end-3)) == 1
pa_sacdet;
pause;
end
end
\ No newline at end of file
%% pb_vSacDet.m
cfn = pb_clean ('cd','U:\Documents\BIOLOGIE\STAGE\MATLAB\Data\test experiment');
path = pb_getdir('cdir',cd);
cd(path)
l = dir('epoched*.mat');
if isempty(1); return; end
fn = l(1).name;n
load(fn);
if ~exist('sacdet','dir')
mkdir('sacdet')
end
path = [path filesep 'sacdet'];
cd(path)
%%
Dlen = length(Data.epoch);
fs = 120;
duration = 3;
samples = duration*fs;
for iB = 1:Dlen
fname = fcheckext(['sacdet_' fn(14:end-5) '_block_' num2str(iB) '_azel'] ,'.hv');
fid = fopen([path filesep fname],'w','l');
AZEL = [Data.epoch(iB).AzGazeEpoched;Data.epoch(iB).ElGazeEpoched];
fwrite(fid,AZEL,'float');
fclose(fid);
fn_csv = [path filesep fname];
VC2csv(fn_csv,fs,samples,1:length(Data.epoch(iB).AzGazeEpoched)/samples);
if ~isfile(fn_csv(1:end-3))==1
pa_sacdet;
pause;
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment