forked from yetianmed/subcortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_regressor.m
35 lines (28 loc) · 988 Bytes
/
task_regressor.m
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
function regressor=task_regressor(TR,T,taskfile)
%taskfile: If using the Custom 3 column format, prepare a plain text file (avoiding editors such as MS Word)
%containing one line for each stimulus associated with the condition to be modelled by this EV.
%Each line must contain three numbers: the onset time (in seconds); the duration (in seconds);
%the relative magnitude of each stimulus (usually set to 1)
% Example:
% taskfile='fear.txt';
% 32.08 18 1
% 74.223 18 1
% 116.365 18 1
%TR: in seconds
%T: number of frames
%Convolve with HRF
Convolve=1; %0=no 1=yes
hrf=spm_hrf(TR);
%Regressor
regressor=zeros(T,1);
t=dlmread(taskfile);
for i=1:size(t,1)
start=t(i,1);
finish=start+t(i,2);
%Convert from seconds to TRs
start=round(start/TR)+1;
finish=round(finish/TR)+1;
regressor(start:finish)=1;
end
if Convolve; regressor=conv(hrf,regressor); end %Convolve with HRF
regressor=regressor(1:T);