-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_ssGC.m
70 lines (54 loc) · 1.92 KB
/
test_ssGC.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
%% computation of multiscale GC with state-space models for simple simulated VAR processes
clear; close all; clc;
%% Parameters
tau=1; %scale (NOTE: for tau=1 computes time-domain state-space GC, (ncoeff is irrelevant))
ncoeff=6; % number of coeff of FIR lowpass filter
N=300; % length of realization
%%% Simulation parameters
M=3;
p=2;
Ak=zeros(M,M,p);
Ak(1,1,1)=0.5;
Ak(2,1,2)=0.5;
Ak(3,1,1)=0.7;
Su=1*eye(M);
Am=[];
for kk=1:p
Am=[Am Ak(:,:,kk)];
end
% stability check
E=eye(M*p);AA=[Am;E(1:end-M,:)];lambda=eig(AA);lambdamax=max(abs(lambda));
if lambdamax>=1
error('The simulated VAR process is not stable');
end
%% GC Analysis
% theoretical GC values
GC = msgc(Am,Su,tau,ncoeff);
% estimated GC values
U=eMVAR_InstModelfilter(N,Su,'StrictlyCausal'); % gaussian innovations with covariance Su
Y=eMVAR_MVARfilter(Am,U); %simulated process
[eAm,eSu]=eMVAR_idMVAR(Y,p,0); %model identification from eMVAR toolbox
eGCss = msgc(eAm,eSu,tau,ncoeff); %Granger causality estimated using ISS models
if tau==1
end
%% display
if tau>1
clc;
disp(['scale ' int2str(tau)])
for ii=1:M
for jj=ii+1:M
disp(['GC ' int2str(ii) '->' int2str(jj) ', theor:' num2str(GC(jj,ii)) ', est.SS:' num2str(eGCss(jj,ii))]);
disp(['GC ' int2str(jj) '->' int2str(ii) ', theor:' num2str(GC(ii,jj)) ', est.SS:' num2str(eGCss(ii,jj))]);
end
end
end
if tau==1
eGCvar=egc_gcMVAR(Y,p); %Granger causality estimated from eGC toolbox (at scale 1)
clc;
for ii=1:M
for jj=ii+1:M
disp(['GC ' int2str(ii) '->' int2str(jj) ', theor:' num2str(GC(jj,ii)) ', est.SS:' num2str(eGCss(jj,ii)) ', est.VAR:' num2str(eGCvar(jj,ii))]);
disp(['GC ' int2str(jj) '->' int2str(ii) ', theor:' num2str(GC(ii,jj)) ', est.SS:' num2str(eGCss(ii,jj)) ', est.VAR:' num2str(eGCvar(ii,jj))]);
end
end
end