-
Notifications
You must be signed in to change notification settings - Fork 2
/
spm_DEM_embed.m
54 lines (46 loc) · 1.62 KB
/
spm_DEM_embed.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
52
53
54
function [y] = spm_DEM_embed(Y,n,t,dt)
% temporal embedding into derivatives
% FORMAT [y] = spm_DEM_embed(Y,n,t,dt)
%__________________________________________________________________________
% Y - (v x N) matrix of v time-series of length N
% n - order of temporal embedding
% t - time {secs} at which to evaluate derivatives (starting at t = 1)
% dt - sampling interval {secs} [default = 1]
%
% y - {n,1}(v x 1) temporal derivatives y[:] <- E*Y(t)
%==========================================================================
% Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
% Karl Friston
% $Id$
% defaults
%--------------------------------------------------------------------------
if nargin < 4, dt = 1; end
% get dimensions
%--------------------------------------------------------------------------
[q N] = size(Y);
t = t/dt;
y = cell(n,1);
[y{:}] = deal(sparse(q,1));
% boundary conditions
%--------------------------------------------------------------------------
k = [1:n] + fix(t - (n + 1)/2);
x = t - min(k) + 1;
i = k < 1;
k = k.*~i + i;
i = k > N;
k = k.*~i + i*N;
% Inverse embedding operator (T): c.f., a Taylor expansion Y(t) <- T*y[:]
%--------------------------------------------------------------------------
for i = 1:n
for j = 1:n
T(i,j) = ((i - x)*dt)^(j - 1)/prod(1:(j - 1));
end
end
% embedding operator: y[:] <- E*Y(t)
%--------------------------------------------------------------------------
E = inv(T);
% embed
%--------------------------------------------------------------------------
for i = 1:n
y{i} = Y(:,k)*E(i,:)';
end