Commit 053ed782 authored by Jesse Heckman's avatar Jesse Heckman
Browse files

clear vesitbular pathway

parent 464e3707
function signal = pb_vBuildSignal(block)
% PB_VBUILDSIGNAL
%
% PB_VBUILDSIGNAL(block) will create the vestibular signals for a given
% experimental block.
%
% See also PB_VPRIME, PB_VSIGNALVC, PB_VSAFETY, PB_VCHECKVELSIGNAL
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
% read signals
signal(1) = block.ver;
signal(2) = block.hor;
for iSig = 1:2
% correct for vestibular chair's inertia.
if strcmp(signal(iSig).type,'sine'); signal(iSig).type = 'predictsine'; end
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [Dat,profile,dur] = pb_vSignalVC(handles)
function [profile,dur] = pb_vSignalVC(handles)
% PB_VSIGNALVC
%
% PB_VSIGNALVC(handles) reads vestibular signal from handles, writes
......@@ -11,57 +11,49 @@ function [Dat,profile,dur] = pb_vSignalVC(handles)
block = handles.block;
bnumber = handles.cfg.blocknumber;
%% READ SIGNAL PARAMETERS
signal(1) = block(bnumber).signal.ver;
signal(2) = block(bnumber).signal.hor;
% Read & create signals
signal = pb_vBuildSignal(block(bnumber).signal);
signal = pb_vSafety(signal);
for iSig = 1:2
if strcmp(signal(iSig).type,'sine'); signal(iSig).type = 'predictsine'; end
end
%% CREATE BASIC SIGNAL
vSignal = pb_vCreateSignal(1, signal(1).duration, 10, signal(1).frequency, signal(1).type);
hSignal = pb_vCreateSignal(1, signal(2).duration, 10, signal(2).frequency, signal(2).type);
%% FINALIZE SIGNAL
Dat.v.x = vSignal.x .* signal(1).amplitude;
Dat.v.t = (0:1:length(Dat.v.x)-1)/10;
profile.v = Dat.v.x;
Dat.h.x = hSignal.x .* signal(2).amplitude;
Dat.h.t = (0:1:length(Dat.h.x)-1)/10;
profile.h = Dat.h.x;
Dat.v.amplitude = signal(1).amplitude;
Dat.h.amplitude = signal(2).amplitude;
% Finalize signals
sigData.v.x = vSignal.x .* signal(1).amplitude;
sigData.v.t = (0:1:length(sigData.v.x)-1)/10;
profile.v = sigData.v.x;
%% CHECK SAFETY FINAL SIGNAL
sigData.h.x = hSignal.x .* signal(2).amplitude;
sigData.h.t = (0:1:length(sigData.h.x)-1)/10;
profile.h = sigData.h.x;
[hSafe,~] = pb_vCheckVelSignal(Dat.h.x);
[vSafe,mvel] = pb_vCheckVelSignal(Dat.v.x);
% Check signal safety
[hSafe,~] = pb_vCheckVelSignal(profile.h);
[vSafe,mvel] = pb_vCheckVelSignal(profile.v);
if ~hSafe || ~vSafe
error(['Vestibular signals were not safe! (velocity exceeds ' num2str(mvel) ')']);
end
%% FEEDBACK GUI
% Feedback GUI
updateBlock(handles, signal);
handles = pb_gethandles(handles);
dur = max([handles.block(bnumber).signal.ver.duration handles.block(bnumber).signal.hor.duration]);
% set axis
axes(handles.signals);
cla; hold on;
handles.signals.YLim = [-50 50];
handles.signals.XLim = [0 dur];
dv = 10 * [0 diff(Dat.v.x)];
dh = 10 * [0 diff(Dat.h.x)];
% plot signals
dv = 10 * [0 diff(profile.v)];
dh = 10 * [0 diff(profile.h)];
t = sigData.v.t;
plot(Dat.v.t,dv,'k');
plot(Dat.h.t,dh,'b');
plot(t,dv,'k');
plot(t,dh,'b');
end
function updateBlock(handles, signal)
......
......@@ -14,7 +14,6 @@ function handles = pb_vStoreData(handles, data)
[~,prefix] = pb_fext(cfg.fname);
fname = [prefix '-' num2str(cfg.trialnumber(2),'%04d') '.vc'];
data = data; %% TO DO: <-- FIX: SELECT DATA FOR TRIAL ONLY
beta = setCFG(cfg); %% TO DO: <-- FIX: SELECT CFGs FOR TRIAL ONLY
save(fname,'data', 'beta', '-mat');
......
......@@ -18,10 +18,10 @@ function pb_vRunExp(handles)
% set handles
pb_setupShow(handles);
handles = pb_gethandles(handles);
handles = pb_getblock(handles);
handles = pb_createdir(handles);
handles = pb_vInitialize(handles, true);
handles = pb_gethandles(handles);
handles = pb_getblock(handles);
handles = pb_createdir(handles);
handles = pb_vInitialize(handles, true);
% set block information
block = handles.block;
......@@ -29,20 +29,19 @@ function pb_vRunExp(handles)
Dat = pb_dataobj(nblocks);
% initialize recordings
rc = pb_runPupil;
[ses,streams] = pb_runLSL;
experimentTime = tic;
rc = pb_runPupil;
[ses,str] = pb_runLSL;
expTime = tic;
%% START BLOCK
% iterate experimental blocks
for iBlck = 1:nblocks
% Runs blocks of trials with a vestibular condition
% set block information
nTrials = length(block(iBlck).trial);
handles = updateCount(handles,'trial','reset');
[sig,profile,dur] = pb_vSignalVC(handles);
nTrials = length(block(iBlck).trial);
handles = updateCount(handles,'trial','reset');
[profile,dur] = pb_vSignalVC(handles);
% start recording
pb_startLSL(ses);
......@@ -51,8 +50,9 @@ function pb_vRunExp(handles)
% start vestibular chair
if ~ismac && ~debug
pb_vCheckServo;
vs = pb_sendServo(profile);
blockTime = tic;
vs = pb_sendServo(profile);
blockTime = tic;
pb_startServo(vs);
pause(6); % allow vestibular chair to get in sync with input signal
end
......@@ -61,19 +61,20 @@ function pb_vRunExp(handles)
% iterate over trials per block
for iTrl = 1:nTrials
% Runs all trials within one block
% setup trial
% setup trial
updateTrial(handles);
stim = handles.block(iBlck).trial(iTrl).stim;
handles.cfg = pb_vClearTrial(stim, handles.cfg);
[~, handles.cfg] = pb_vSetupTrial(stim, handles.cfg);
trialTime = tic;
% run trial
pb_vRunTrial(handles.cfg.zBus, handles.cfg.trialdur);
pb_vTraces(handles);
handles = pb_vStoreData(handles, sig);
% save trial
handles = pb_vStoreData(handles, profile);
handles.cfg = updateCount(handles.cfg,'trial','count');
toc(trialTime);
end
......@@ -95,9 +96,9 @@ function pb_vRunExp(handles)
pb_stopLSL(ses);
% store data
Dat(iBlck).event_data = streams(1).read;
Dat(iBlck).pupil_labs = streams(2).read;
Dat(iBlck).optitrack = streams(3).read;
Dat(iBlck).event_data = str(1).read;
Dat(iBlck).pupil_labs = str(2).read;
Dat(iBlck).optitrack = str(3).read;
Dat(iBlck).block_info = handles.block(iBlck);
% update block information
......@@ -111,7 +112,7 @@ function pb_vRunExp(handles)
pb_vEndExp;
pb_vStoreBlockDat(handles.cfg, Dat);
pb_vInitialize(handles, false);
toc(experimentTime)
toc(expTime)
end
%-- GUI feedback functions --%
......
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