-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspm_ssm2s.m
74 lines (59 loc) · 2.03 KB
/
spm_ssm2s.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function [s,u] = spm_ssm2s(P,M,TOL)
% Converts state-space (M) representation to eigenspectrum
% FORMAT [s,u] = spm_ssm2s(P,M)
%
% P - model parameters
% M - model (with flow M.f and expansion point M.x and M.u)
% TOL - optional upper bound for principality exponent (default -4)
%
% S - (sorted) eigenspectrum or Lyapunov exponents
% V - associated eigenvectors
%
% csd - cross spectral density
%__________________________________________________________________________
% Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_ssm2s.m 6233 2014-10-12 09:43:50Z karl $
% preliminaries
%--------------------------------------------------------------------------
if nargin < 3, TOL = -4; end
% Steady state solution
%--------------------------------------------------------------------------
M.x = spm_dcm_neural_x(P,M);
try
M.u;
catch
M.u = zeros(M.l,1);
end
% Jacobian and delay operator - if not specified already
%--------------------------------------------------------------------------
if nargout(M.f) >= 3
[f,dfdx,D] = feval(M.f,M.x,M.u,P,M);
elseif nargout(M.f) == 2
[f,dfdx] = feval(M.f,M.x,M.u,P,M);
D = 1;
else
dfdx = spm_diff(M.f,M.x,M.u,P,M,1);
D = 1;
end
dfdx = D*dfdx;
dfdu = D*spm_diff(M.f,M.x,M.u,P,M,2);
[u,s] = eig(full(dfdx),'nobalance');
s = diag(s);
% eigenvectors
%--------------------------------------------------------------------------
u = u*diag(pinv(u)*dfdu);
% condition slow eigenmodes
%--------------------------------------------------------------------------
s = 1j*imag(s) + min(real(s),TOL);
% principal eigenmodes (highest imaginary value)
%--------------------------------------------------------------------------
[d,i] = sort(imag(s),'descend');
u = u(:,i);
s = s(i);
% principal eigenmodes (highest real value)
%--------------------------------------------------------------------------
j = find(~imag(s));
[d,i] = sort(real(s(j)),'descend');
u(:,j) = u(:,j(i));
s(j) = s(j(i));