
% Copyright 2020 The MathWorks, Inc.

function [A,B,C,D] = timeVariantAR1ParamMap(params)
% Time-varying state-space model parameter mapping function example. This
% function maps the vector params to the state-space matrices (A, B, C, and
% D). From periods 1 through 10, the state model is an AR(1)model, and from
% periods 11 through 20, the state model is possibly a different AR(1)
% model. The measurement equation is the same throughout the time span.
    A1 = {params(1)};
    A2 = {params(2)};
    varu1 = exp(params(3));  % Positive variance constraints
    varu2 = exp(params(4));
    B1 = {sqrt(varu1)}; 
    B2 = {sqrt(varu2)};
    C = params(5);
    vare1 = exp(params(6));
    D = sqrt(vare1);
    A = [repmat(A1,10,1); repmat(A2,10,1)];
    B = [repmat(B1,10,1); repmat(B2,10,1)];
end
