about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/Kalman/SS_to_AR.m
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/Kalman/SS_to_AR.m')
-rw-r--r--sourcecodes/bnt-master/Kalman/SS_to_AR.m22
1 files changed, 22 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/Kalman/SS_to_AR.m b/sourcecodes/bnt-master/Kalman/SS_to_AR.m
new file mode 100644
index 00000000..084b7141
--- /dev/null
+++ b/sourcecodes/bnt-master/Kalman/SS_to_AR.m
@@ -0,0 +1,22 @@
+function [coef, C] = SS_to_AR(F, Q, k, diagonal)
+%
+% Extract the parameters of a vector autoregresssive process of order k from the state-space form.
+% [coef, C] = SS_to_AR(F, Q, k, diagonal)
+
+if nargin<4, diagonal = 0; end
+
+s = length(Q) / k;
+bs = s*ones(1,k);
+coef = zeros(s,s,k);
+for i=1:k
+  if diagonal
+    coef(:,:,i) = diag(diag(F(block(1,bs), block(i,bs))));
+  else
+    coef(:,:,i) = F(block(1,bs), block(i,bs));
+  end
+end
+C = Q(block(1,bs), block(1,bs));
+if diagonal
+  C = diag(diag(C));
+end
+%C = sqrt(Q(block(1,bs), block(1,bs))); % since cov(1,1) of full vector = C C'