Commit 6db07b65 authored by Jesse Heckman's avatar Jesse Heckman
Browse files

vPrime updates

parent 5fe6b4c2
......@@ -59,6 +59,8 @@ function pb_vPrimeGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% Update handles structure
guidata(hObject, handles);
set(handles.editLoad,'string',cd);
if isunix; cd('/Users/jjheckman/Documents/Data'); end
% UIWAIT makes pb_vPrimeGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
......@@ -144,7 +146,8 @@ function buttonRun_Callback(hObject, eventdata, handles)
Exp.recording = get(handles.editRec,'string');
disp(['Experimenter: ' Exp.experimenter newline 'Expfile: ' Exp.expfile newline 'Subject ID: ' Exp.SID newline 'Recording: ' Exp.recording newline]);
pb_vRunExp(Exp,handles)
pb_vRunExp(Exp,handles);
end
end
......@@ -153,7 +156,8 @@ function buttonClose_Callback(hObject, eventdata, handles)
% hObject handle to buttonClose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcf);
close(handles.figure1);
end
% --- Executes on button press in buttonLoad.
......@@ -182,7 +186,6 @@ function editPart_Callback(hObject, eventdata, handles)
% Hints: get(hObject,'String') returns contents of editPart as text
% str2double(get(hObject,'String')) returns contents of editPart as a double
% --- Executes during object creation, after setting all properties.
end
......
function D = pb_vCreateSignal(N, dur, SR, freq, type)
% PB_VCREATESIGNAL()
%
% PB_VCREATESIGNAL() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
for i=1:N
switch type
case 'noise'
[D(i).x,D(i).t] = VC_noisesignal(0, dur, SR);
%plot(D(i).t,D(i).x); hold on;
case 'sine'
[D.x,D.t] = VC_sinesignal(dur, SR, freq);
%plot(D.t,D.x); hold on;
case 'predictsine'
[D.x,D.t] = VC_predictedsine(dur, SR, freq);
%plot(D.t,D.x); hold on;
case 'turn'
[D.x,D.t] = VC_turnsignal(dur, SR);
%plot(D.t,D.x);
otherwise
error('False type specification');
end
end
end
function [x,t] = VC_noisesignal(mu, dur, SR)
% function generates a noise signal with mean mu, length dur and frequency freq.
% noise signal
sigma = 0;
t = 0:1/SR:dur;
x = mu+sigma;
x = x+randn(length(t),1);
% cheby filtered signal
n = 12;
Ws = 1;
Rs = 80;
LPfil = designfilt('lowpassiir', 'FilterOrder', n,...
'StopbandFrequency', Ws,...
'StopbandAttenuation', Rs,...
'SampleRate', 10);
x = filtfilt(LPfil,x);
% tukey window
L = length(t);
x = x.* tukeywin(L,0.25);
end
function [x,t] = VC_sinesignal(dur, SR, freq)
% function generates a sine signal
w = freq*2*pi;
t = 0:1/SR:dur;
x = sin(w*t);
L = length(t);
x = x.* tukeywin(L,0.25)';
end
function [x,t] = VC_predictedsine(dur, SR, freq)
% function generates a sine signal that in theory should generete an
% perfect sine output: y(t)=sin(wt).
a = 1.39;
b = 1.4;
w = freq*2*pi;
t = 0:1/SR:dur;
x = (b*sin(w*t) + w*cos(w*t))/a;
L = length(t);
x = x.* tukeywin(L,0.25)';
end
function [x,t] = VC_turnsignal(dur, SR)
% function will create turn signal of length dur
t = 0:1/SR:dur;
v = randn(1,1);
x = v*t;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function Dat = pb_vRunVC(signal)
% PB_VRUNVC()
%
% PB_VRUNVC() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
dur = 10;
amp = 10;
type = 'sine';
vSignal = pb_vCreateSignal(1, dur, 10, 1, type);
hSignal = pb_vCreateSignal(1, dur, 10, 1, type);
Dat.v.x = vSignal.x .* amp;
Dat.v.t = (0:1:length(Dat.v.x)-1)/10;
Dat.h.x = hSignal.x .* 0;
Dat.h.t = (0:1:length(Dat.h.x)-1)/10;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -8,43 +8,87 @@ function pb_vRunExp(expinfo,h)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% INITIALIZE
% load & read experiment
[block, cfg] = pb_vReadExp(expinfo.expfile); % struct
nblocks = cfg.Blocks;
nTotTrials = cfg.Trials;
[block, cfg] = pb_vReadExp(expinfo.expfile); % struct
nblocks = cfg.Blocks;
nTotTrials = cfg.Trials;
cnt = 0;
bDat(nblocks) = struct; % pre-allocate data for speed
tDat(nTotTrials) = struct;
set(h.buttonClose, 'Enable', 'off') % avoid closing GUI during executing run function
set(h.buttonRun, 'Enable', 'off');
set(h.buttonLoad, 'Enable', 'off')
%% BODY
% iterate experiment
% Iterate experiment
for iBlock = 1:nblocks
% Runs blocks of trials with a vestibular condition
nTrials = length(block(iBlock).trial);
signal = block(iBlock).signal;
pb_vSafety(signal); % Checks for safe vestibular parameters!!
signal = block(iBlock).signal;
updateBlock(h,iBlock,signal);
pb_vSafety(signal); % Checks for safe vestibular parameters!!
for iTrial = 1:nTrials
%pb_vClearTrial();
%pb_vRecordData();
%pb_vRunTrial(experiment(iTrial));
%pb_vFeedbackGUI();
end
bDat(iBlock).signal = pb_vRunVC(signal);
% Plot signals
h.signals; cla; hold on; col = pb_selectcolor(2,2); pause(.1);
plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'Color',col(1,:));
plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'Color',col(2,:));
for iTrial = 1:nTrials
% Runs all trials within one block
cnt = cnt+1;
updateTrial(h, iTrial, cnt, nTotTrials, tDat);
%pb_vClearTrial();
%pb_vRecordData();
%pb_vRunTrial(experiment(iTrial));
%pb_vFeedbackGUI();
pause(1);
end
end
%% CHECK OUT
% store data
set(h.buttonClose, 'Enable', 'on');
set(h.buttonRun, 'Enable', 'on');
set(h.buttonLoad, 'Enable', 'on');
end
function updateBlock(h, iBlock, signal)
% Updates the block information to the GUI
bn = pb_sentenceCase(num2str(iBlock,'%03d')); % count block
set(h.Bn,'string',bn);
vs = ['V = ' pb_sentenceCase(signal.ver.type) ... % VC stim
', H = ' pb_sentenceCase(signal.hor.type)];
set(h.Vs,'string',vs);
end
function updateTrial(h, iTrial, cnt, nTotTrials, tDat)
% Updates the trial information to the GUI
h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials)]; % counting title
tn = num2str(iTrial,'%03d'); % blocktrial
set(h.Tn,'string',tn)
updateDat(h, tDat);
end
function updateDat(h, Dat)
% Updates the visual feedback data
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
......
function str = pb_sentenceCase(str)
% PB_SENTENCECASE()
%
% PB_SENTENCECASE() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if isempty(str)
return
elseif length(str) == 1
str = upper(str(1));
elseif length(str) == 2
str = [upper(str(1)) lower(str(2))];
else
str = [upper(str(1)) lower(str(2:end))];
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
Supports Markdown
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