forked from jooh/matlab-studytools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanTiming.m
More file actions
61 lines (55 loc) · 2.11 KB
/
Copy pathScanTiming.m
File metadata and controls
61 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
classdef ScanTiming < Timing
% Timing object for running events relative to scans from scannersync
properties
tr = [];
end
methods
function t = ScanTiming(varargin)
% Set pulse and run through dummy volumes, provide a first
% estimate of tr.
% t = ScanTiming(varargin)
t = varargs2structfields(varargin,t);
t.units = 'scans';
end
function scan = begin(self)
err = invoke(self.scanobj,'StartExperiment',self.tr);
assert(~err,'StartExperiment failed!');
% figure out tr
oldtr = self.tr;
% should now have an ok idea of what the actual tr is
self.estimatetr;
assert(isempty(oldtr) || (abs(oldtr-self.tr)<200),...
['tr diverges by more than 200 ms from tr estimate :' ...
'%.2f vs %.2f'],oldtr,self.tr);
% set first scan as whatever we've got at this point
[self.first,scan] = deal(self.check);
end
function tim = check(self)
% returns the current estimated scan number and updates the
% previous and current properties
% tim = check;
self.previous = self.current;
[self.current,tim] = deal(invoke(self.scanobj,...
'GetLastPulseNum',0));
end
function waituntil(self,abstime)
% keep synchronising until check returns abstime
% waituntil(vol)
ch = self.check;
for n = 1:(abstime-ch)
invoke(self.scanobj,'SynchroniseExperiment',1,0);
end
end
function syncseconds(self,s)
% update tr estimate by waiting around for s duration
% syncseconds(s)
invoke(self.scanobj,'CheckPulseSynchronyForTime',s*1e3);
end
function tr = estimatetr(self)
% return an estimate of the tr (in ms) from scanobj. Will be more
% accurate the more time you spend on syncseconds or waituntil.
% tr = estimatetr;
[tr,self.tr] = deal(invoke(self.scanobj,'GetMeasuredTR'));
end
end
end