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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [F,H,Q,R,initx, initV] = AR_to_SS(coef, C, y)
Daniel@0 2 %
Daniel@0 3 % Convert a vector auto-regressive model of order k to state-space form.
Daniel@0 4 % [F,H,Q,R] = AR_to_SS(coef, C, y)
Daniel@0 5 %
Daniel@0 6 % X(i) = A(1) X(i-1) + ... + A(k) X(i-k+1) + v, where v ~ N(0, C)
Daniel@0 7 % and A(i) = coef(:,:,i) is the weight matrix for i steps ago.
Daniel@0 8 % We initialize the state vector with [y(:,k)' ... y(:,1)']', since
Daniel@0 9 % the state vector stores [X(i) ... X(i-k+1)]' in order.
Daniel@0 10
Daniel@0 11 [s s2 k] = size(coef); % s is the size of the state vector
Daniel@0 12 bs = s * ones(1,k); % size of each block
Daniel@0 13
Daniel@0 14 F = zeros(s*k);
Daniel@0 15 for i=1:k
Daniel@0 16 F(block(1,bs), block(i,bs)) = coef(:,:,i);
Daniel@0 17 end
Daniel@0 18 for i=1:k-1
Daniel@0 19 F(block(i+1,bs), block(i,bs)) = eye(s);
Daniel@0 20 end
Daniel@0 21
Daniel@0 22 H = zeros(1*s, k*s);
Daniel@0 23 % we get to see the most recent component of the state vector
Daniel@0 24 H(block(1,bs), block(1,bs)) = eye(s);
Daniel@0 25 %for i=1:k
Daniel@0 26 % H(block(1,bs), block(i,bs)) = eye(s);
Daniel@0 27 %end
Daniel@0 28
Daniel@0 29 Q = zeros(k*s);
Daniel@0 30 Q(block(1,bs), block(1,bs)) = C;
Daniel@0 31
Daniel@0 32 R = zeros(s);
Daniel@0 33
Daniel@0 34 initx = zeros(k*s, 1);
Daniel@0 35 for i=1:k
Daniel@0 36 initx(block(i,bs)) = y(:, k-i+1); % concatenate the first k observation vectors
Daniel@0 37 end
Daniel@0 38
Daniel@0 39 initV = zeros(k*s); % no uncertainty about the state (since perfectly observable)