%% Explicitly Create Diffuse State-Space Model Containing Observation Error
% Create a diffuse state-space model containing two random walk states. The observations are the sum of the two states, plus Gaussian error. Symbolically, the equation is
% \left[
% {\begin{array}{*{20}{c}}{{x_{t,1}}}\\{{x_{t,2}}}\end{array}} \right] =
% \left[ {\begin{array}{*{20}{c}}1&0\\0&1\end{array}}
% \right]\left[ {\begin{array}{*{20}{c}}{{x_{t - 1,1}}}\\{{x_{t -
% 1,2}}}\end{array}} \right] + \left[
% {\begin{array}{*{20}{c}}{\sigma_1} & 0\\0 & \sigma_2\end{array}} \right]\left[
% {\begin{array}{*{20}{c}}{{u_{t,1}}}\\{{u_{t,2}}}\end{array}}
% \right]
% {y_t} = \left[ {\begin{array}{*{20}{c}}1&1\end{array}}
% \right]\left[
% {\begin{array}{*{20}{c}}{{x_{t,1}}}\\{{x_{t,2}}}\end{array}}
% \right]+\sigma_3\varepsilon_t.
% Define the state-transition matrix.

A = [1 0; 0 1];

%
% Define the state-disturbance-loading matrix.

B = [NaN 0; 0 NaN];

%
% Define the measurement-sensitivity matrix.

C = [1 1];

%
% Define the observation-innovation matrix.

D = NaN;

%
% Create a vector that specifies that both states are nonstationary.

StateType = [2; 2];

%
% Create the state-space model using dssm.

 Mdl = dssm(A,B,C,D,'StateType',StateType)

% Mdl is an dssm model containing unknown parameters. A detailed summary of Mdl prints to the Command Window.
% Pass the data and Mdl to estimate to estimate the parameters. During estimation, the initial state variances are Inf, and estimate implements the diffuse Kalman filter.
% Copyright 2015 The MathWorks, Inc.