forked from anne-urai/Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeconvTseries.m
executable file
·51 lines (46 loc) · 1.63 KB
/
deconvTseries.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function hdrols = deconvTseries(scm,dat,err)
% hdrols = deconvTseries(scm,dat,err)
%
% computes a ordinary least squares estimate
% of hemodynamic response function from
% from ER-fMRI time series (dat) and stimulus convolution
% matrix (scm)
%
% dat = scm * hdr + noise
% hdr_ols = inv(scm' * scm) * scm' * dat
%
% assumes temporally uncorrelated noise,
% i.e.: COV(noise) = var(noise) * I
% hdr_ols is unbiased estimate, that is,
% does not assume particular shape of response
% (Dale A, HBM, 1999)
%
% dat is column vector of length Ndatsmp,
% scm is horizontal concatenation of Ncond individual stimulus
% convolution matrices, i.e., Ndatsmp x Nestsmp arrays,
% where Nestsmp is the length (in samples) of HDR estimate,
% and Ndatsmp is the length (in samples) of measured
% time series
% if error == 1, and error estimate for each parameter is computed
dat = dat(:);
% estimate HDR
% these alternatives should be equivalent
%hdrpar = inv(scm'*scm)*scm'*dat;
%hdrpar = scm\dat;
hdrpar = pinv(scm)*dat;
predic = scm*hdrpar;
if err % estimate error
%double-check error estimate - standard error?
[n,k] = size(scm);
ssq = (norm(dat - predic))^2;
noisevar = ssq/(n-k);
cov = inv(scm'*scm);
%cov = (scm'*scm).^-1;
hdrerr = diag(cov)*noisevar;
else
hdrerr = [];
end
% collect the results
hdrols.par = hdrpar; % vertical concetenation of HDR estimates for each stim type in scn
hdrols.err = hdrerr; % vertical concetenation of corresponding errors
hdrols.predic = predic;