annotate toolboxes/FullBNT-1.0.7/Kalman/AR_to_SS.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [F,H,Q,R,initx, initV] = AR_to_SS(coef, C, y)
wolffd@0 2 %
wolffd@0 3 % Convert a vector auto-regressive model of order k to state-space form.
wolffd@0 4 % [F,H,Q,R] = AR_to_SS(coef, C, y)
wolffd@0 5 %
wolffd@0 6 % X(i) = A(1) X(i-1) + ... + A(k) X(i-k+1) + v, where v ~ N(0, C)
wolffd@0 7 % and A(i) = coef(:,:,i) is the weight matrix for i steps ago.
wolffd@0 8 % We initialize the state vector with [y(:,k)' ... y(:,1)']', since
wolffd@0 9 % the state vector stores [X(i) ... X(i-k+1)]' in order.
wolffd@0 10
wolffd@0 11 [s s2 k] = size(coef); % s is the size of the state vector
wolffd@0 12 bs = s * ones(1,k); % size of each block
wolffd@0 13
wolffd@0 14 F = zeros(s*k);
wolffd@0 15 for i=1:k
wolffd@0 16 F(block(1,bs), block(i,bs)) = coef(:,:,i);
wolffd@0 17 end
wolffd@0 18 for i=1:k-1
wolffd@0 19 F(block(i+1,bs), block(i,bs)) = eye(s);
wolffd@0 20 end
wolffd@0 21
wolffd@0 22 H = zeros(1*s, k*s);
wolffd@0 23 % we get to see the most recent component of the state vector
wolffd@0 24 H(block(1,bs), block(1,bs)) = eye(s);
wolffd@0 25 %for i=1:k
wolffd@0 26 % H(block(1,bs), block(i,bs)) = eye(s);
wolffd@0 27 %end
wolffd@0 28
wolffd@0 29 Q = zeros(k*s);
wolffd@0 30 Q(block(1,bs), block(1,bs)) = C;
wolffd@0 31
wolffd@0 32 R = zeros(s);
wolffd@0 33
wolffd@0 34 initx = zeros(k*s, 1);
wolffd@0 35 for i=1:k
wolffd@0 36 initx(block(i,bs)) = y(:, k-i+1); % concatenate the first k observation vectors
wolffd@0 37 end
wolffd@0 38
wolffd@0 39 initV = zeros(k*s); % no uncertainty about the state (since perfectly observable)