ar_to_ss.m
来自「基于matlab的卡尔曼滤波程序对相关研究有借鉴价值」· M 代码 · 共 40 行
M
40 行
function [F,H,Q,R,initx, initV] = AR_to_SS(coef, C, y)%% Convert a vector auto-regressive model of order k to state-space form.% [F,H,Q,R] = AR_to_SS(coef, C, y)% % X(i) = A(1) X(i-1) + ... + A(k) X(i-k+1) + v, where v ~ N(0, C)% and A(i) = coef(:,:,i) is the weight matrix for i steps ago.% We initialize the state vector with [y(:,k)' ... y(:,1)']', since% the state vector stores [X(i) ... X(i-k+1)]' in order.[s s2 k] = size(coef); % s is the size of the state vectorbs = s * ones(1,k); % size of each blockF = zeros(s*k);for i=1:k F(block(1,bs), block(i,bs)) = coef(:,:,i);endfor i=1:k-1 F(block(i+1,bs), block(i,bs)) = eye(s);endH = zeros(1*s, k*s);% we get to see the most recent component of the state vector H(block(1,bs), block(1,bs)) = eye(s); %for i=1:k% H(block(1,bs), block(i,bs)) = eye(s);%endQ = zeros(k*s);Q(block(1,bs), block(1,bs)) = C;R = zeros(s);initx = zeros(k*s, 1);for i=1:k initx(block(i,bs)) = y(:, k-i+1); % concatenate the first k observation vectorsendinitV = zeros(k*s); % no uncertainty about the state (since perfectly observable)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?