function[AA,CC]=avg(A,C,m)
%function[AA,CC]=avg(A,C,m)
%   Prepares a system for analysis of aggregation over time with
%   "integrated" or summed data.
%   The model governing the state vector is
%
%       x(t+1) = A*x(t) +  C*w(t+1)
%   We want to form the state space system
%
%       z(t+1) = AA*z(t) + CC*w(t+1)
%
%   where z(t) = [x(t)',x(t-1)', ... ,x(t-m+1)']'.
%   Here AA and CC are given by
%
%           A 0 0 ... 0             C
%     AA =  I 0 0 ... 0       CC =  0
%            ...
%           0 0 0   I 0             0
%
%   The user must input A, C, and m.
%   SEE ALSO: AGGREG.M
n=max(size(A));
[r1,r2]=size(C);
nm=n*(m-1);
AA=[A,zeros(n,nm)];
AA=[AA;eye(nm),zeros(nm,n)];
CC=[C;zeros(nm,r2)];
