Debian Codegraph @

tests/kalman/likelihood/simul_state_space_model.m

raw
1 function observed_data = simul_state_space_model(T,R,Q,mf,nobs,H)
2 pp = length(mf);
3 mm = length(T);
4 rr = length(Q);
5
6 upper_cholesky_Q = chol(Q);
7 if nargin>5 && ~isempty(H)
8 upper_cholesky_H = chol(H);
9 end
10
11 state_data = zeros(mm,1);
12
13 if (nargin==5 || isempty(H))
14 for t = 1:nobs
15 state_data = T*state_data + R* upper_cholesky_Q * randn(rr,1);
16 observed_data(:,t) = state_data(mf);
17 end
18 elseif (nargin==6 && ~isempty(H))
19 for t = 1:nobs
20 state_data = T*state_data + R* upper_cholesky_Q * randn(rr,1);
21 observed_data(:,t) = state_data(mf);
22 end
23 observed_data = observed_data + upper_cholesky_H * randn(pp,nobs);
24 else
25 error('simul_state_space_model:: I don''t understand what you want!!!')
26 end