Commit c3df797e authored by Jesse Heckman's avatar Jesse Heckman
Browse files

update vPrime

parent 8c82c81e
......@@ -6,7 +6,7 @@ function pb_vClearTrial(cnt,blck,trl)
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
disp([newline '<strong>New Trial started...</strong> '...
newline ' Trial: ' num2str(cnt) ' (B' num2str(blck) 'T' num2str(trl) ')']);
end
......
function D = pb_vCreateSignal(N, dur, SR, freq, type)
function D = pb_vCreateSignal(N, dur, SR, freq, type, varargin)
% PB_VCREATESIGNAL()
%
% PB_VCREATESIGNAL() ...
......@@ -6,30 +6,28 @@ function D = pb_vCreateSignal(N, dur, SR, freq, type)
% 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
dshow = pb_keyval('dshow',varargin,'false');
D(N) = struct;
for i=1:N
switch type
case 'noise'
[D(i).x,D(i).t] = VC_noisesignal(0, dur, SR);
case 'sine'
[D(i).x,D(i).t] = VC_sinesignal(dur, SR, freq);
case 'predictsine'
[D(i).x,D(i).t] = VC_predictedsine(dur, SR, freq);
case 'turn'
[D(i).x,D(i).t] = VC_turnsignal(dur, SR);
otherwise
error('False type specification');
end
end
if dshow; figure(); hold on; for i=1:N; plot(D(i).t,D(i).x); pb_nicegraph; 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
......@@ -92,7 +90,6 @@ function [x,t] = VC_turnsignal(dur, SR)
t = 0:1/SR:dur;
v = randn(1,1);
x = v*t;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
......@@ -7,6 +7,7 @@ function Dat = pb_vRunVC(signal)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% CREATE SIGNALS
vSignal = pb_vCreateSignal(1, signal(1).duration, 10, 1, signal(1).type);
hSignal = pb_vCreateSignal(1, signal(2).duration, 10, 1, signal(2).type);
......@@ -14,6 +15,54 @@ function Dat = pb_vRunVC(signal)
Dat.v.t = (0:1:length(Dat.v.x)-1)/10;
Dat.h.x = hSignal.x .* signal(2).amplitude;
Dat.h.t = (0:1:length(Dat.h.x)-1)/10;
%% RUN CHAIR
profile.v = Dat.v.x;
profile.h = Dat.h.x;
%% excecute profile
dur = max([signal(1).duration signal(2).duration]);
send_profile(profile);
run_profile(dur);
%[sv,pv] = read_profile;
%% save data
Dat.signal = [1 1];
Dat.amplitude = [signal(1).amplitude signal(2).amplitude];
%Dat.sv = sv;
%Dat.pv = pv;
end
function send_profile(profile)
disp('writing profile to servo');
%vs = vs_servo;
%vs.write_profile(profile.v,profile.h);
%delete(vs);
end
function [sv,pv]=read_profile
%vs=vs_servo;
%[sv.vertical,sv.horizontal] = vs.read_profile_sv;
%[pv.vertical,pv.horizontal] = vs.read_profile_pv;
%delete(vs);
end
function run_profile(dur)
%vs=vs_servo;
%vs.enable;
%pause(1);
%vs.start;
%disp('started');
%pause(dur+5);
%vs.stop;
%disp('stopped');
%vs.disable;
%disp('done');
%delete(vs);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
......@@ -166,7 +166,7 @@ function cfg = hread(fid,cfg)
end
function signal = readVest(line)
types = {'none','sine','noise','step'};
types = {'none','sine','noise','turn'};
n = str2num(erase(sscanf(line,'%s',2),sscanf(line,'%s',1)))+1;
type = types{n};
signal.type = type;
......
......@@ -23,7 +23,11 @@ function pb_vRunExp(expinfo,h)
set(h.buttonRun, 'Enable', 'off')
set(h.buttonLoad, 'Enable', 'off')
h.signals; cla;
% Ready feedback plots
axes(h.signals); cla;
axes(h.eTrace); cla; h.eTrace.YLim = [0 300]; h.eTrace.XLim = [0 2.5];
axes(h.hTrace); cla; h.hTrace.YLim = [0 300]; h.hTrace.XLim = [0 2.5];
%% BODY
% Iterate experiment
......@@ -33,21 +37,24 @@ function pb_vRunExp(expinfo,h)
% Runs blocks of trials with a vestibular condition
nTrials = length(block(iBlock).trial);
signal(1) = block(iBlock).signal.ver;
%% RUN CHAIR
% read signals
signal(1) = block(iBlock).signal.ver;
signal(2) = block(iBlock).signal.hor;
signal = pb_vSafety(signal);
updateBlock(h,iBlock,signal);
pb_vSafety(signal); % Checks for safe vestibular parameters!!
bDat(iBlock).signal = pb_vRunVC(signal);
% run chair
bDat(iBlock).signal = pb_vRunVC(signal);
% Plot signals
h.signals; cla; hold on;
%% PLOT SIGNALS
% set axis and plot signals
axes(h.signals); cla; hold on;
h.signals.YLim = [-50 50];
col = pb_selectcolor(2,2);
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,:));
plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'k');
plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'b');
updateBlock(h,iBlock,signal);
for iTrial = 1:nTrials
% Runs all trials within one block
......@@ -59,14 +66,47 @@ function pb_vRunExp(expinfo,h)
%pb_vRunTrial(experiment(iTrial));
%pb_vFeedbackGUI();
pause(1);
%% PLOT TRACES
% head trace
axes(h.hTrace); hold on;
ws = 20; b = (1/ws)*ones(1,ws); a = 1;
x = 0:.05:2.5;
y = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
y = filter(b,a,y) .* tukeywin(length(x),1)';
plot(x,y);
% eye trace
axes(h.eTrace); hold on;
ws = 20; b = (1/ws)*ones(1,ws); a = 1;
x = 0:.05:2.5;
y = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
y = filter(b,a,y) .* tukeywin(length(x),1)';
plot(x,y);
% highlight active traces
te = pb_fobj(h.eTrace,'Type','Line');
th = pb_fobj(h.hTrace,'Type','Line');
col = pb_selectcolor(10,5);
for iT = 1:length(th)
switch iT
case length(th)
th(iT).Color = col(10,:);
te(iT).Color = col(10,:);
otherwise
th(iT).Color = col(1,:);
te(iT).Color = col(1,:);
end
end
end
pause(2)
pause(1)
end
%% CHECK OUT
% store data
disp([newline newline 'Experiment finished!'])
set(h.buttonClose, 'Enable', 'on');
set(h.buttonRun, 'Enable', 'on');
set(h.buttonLoad, 'Enable', 'on');
......@@ -90,7 +130,6 @@ function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
tn = num2str(iTrial,'%03d'); % blocktrial
set(h.Tn,'string',tn)
end
......
function pb_vSafety(signal)
function signal = pb_vSafety(signal)
% PB_VSAFETY()
%
% PB_VSAFETY() ...
......@@ -9,19 +9,23 @@ function pb_vSafety(signal)
if ~strcmp(signal(2).type,'none')
if signal(2).duration > 300
error('Unsafe signal: Horizontal duration too long!')
warning('Unsafe signal: Horizontal duration too long. Duration reduced to 300.' );
signal(2).duration = 300;
end
if signal(2).amplitude > 20
error('Unsafe signal: Horizontal amplitude too large!')
warning('Unsafe signal: Horizontal amplitude too large. Amplitude reduced to 20');
signal(2).amplitude = 20;
end
end
if ~strcmp(signal(1).type,'none')
if signal(1).duration > 300
error('Unsafe signal: Vertical duration too long!')
warning('Unsafe signal: Vertical duration too long!');
signal(1).duration = 300;
end
if signal(1).amplitude > 50
error('Unsafe signal: Horizontal amplitude too large!')
if signal(1).amplitude > 40
warning('Unsafe signal: Horizontal amplitude too large!');
signal(2).amplitude = 40;
end
end
end
......
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