-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patheMVAR_InstModelfilter.m
66 lines (52 loc) · 2.3 KB
/
eMVAR_InstModelfilter.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
%% realization of the instantaneous model : U = L*W
%%% OUTPUT
% U: N*M matrix of filtered noises
% INPUT
% N data length
% C: input covariance matrix (may be interpreted as Su or Sw, see above)
% B0: M*M matrix of instantaneous effects (when relevant)
% when flag='StrictlyCausal':
% given Su, applies Cholesky decomposition to find L and Sw
% then generates U = L*W, for a realization of gaussian W of variance Sw
% when flag='ExtendedGauss':
% given Sw and B(0), computes L=[I-B(0)]^(-1)
% then generates U = L*W, for a realization of gaussian W of variance Sw
% when flag='ExtendedNonGauss':
% given Swand B(0), computes L=[I-B(0)]^(-1)
% then generates U = L*W, for a realization of nongaussian W of variance Sw
function U=eMVAR_InstModelfilter(N,C,flag,B0)
error(nargchk(3,4,nargin));%min and max input arguments
M=size(C,1);
switch flag
case {'StrictlyCausal'} % C is Su
[L,Sw]=eMVAR_choldiag(C);
W = randn(M,N); % W independent and gaussian
for m=1:M % This normalizes W to have the appropriate variance (and zero mean)
W(m,:)=sqrt(Sw(m,m))*(W(m,:)-mean(W(m,:)))/std(W(m,:));
end
U=L*W;
case {'ExtendedGauss'} % C is Sw
invL=eye(M)-B0;
if det(invL)==0, error('B0 is not invertible, ill-conditioned problem!'), end;
L=inv(invL);
W = randn(M,N); % W independent and gaussian
for m=1:M % This normalizes W to have the appropriate variance (and zero mean)
W(m,:)=sqrt(C(m,m))*(W(m,:)-mean(W(m,:)))/std(W(m,:));
end
U=L*W;
case {'ExtendedNonGauss'} % C is Sw
invL=eye(M)-B0;
if det(invL)==0, error('B0 is not invertible, ill-conditioned problem!'), end;
L=inv(invL);
%note: here we generate W independent but non-Gaussian
% Nonlinearity exponent, selected to lie in [0.5, 0.8] or [1.2, 2.0]. (<1 gives subgaussian, >1 gives supergaussian)
q = rand(M,1)*1.1+0.5;
ind = find(q>0.8);
q(ind) = q(ind)+0.4;
% This generates the disturbance variables, which are mutually independent, and non-gaussian
W = randn(M,N);
W = sign(W).*(abs(W).^(q*ones(1,N)));
% This normalizes the disturbance variables to have the appropriate scales
W = W./( ( sqrt(mean((W').^2)') ./ sqrt(diag(C)) )*ones(1,N) );
U=L*W;
end