% Stochastic realization test problems
% Reference:
% Liu, Z. and Vandenberghe, L.
% Semidefinite programmming methods for system realization and
% identification. Section II.
% This generates problems
%
% bx is measurement matrix of size m by n(i+j-1).
% q is an m by n(i+j-1) matrix whose first n*j rows are one and zero otherwise.
%

% clc

m = 40; j = 200;

n = m; p = m;

r = 10;
i = 2*r+1;

T = 999;

A=randn(r,r);
A=A/norm(A); % normalize A
B=randn(r,p);
B=B/norm(B); % normalize B
C=randn(m,r);
C=C/norm(C);

x = randn(r,1);

ynew = zeros(n,T+1);

for k = 1:T+1  
  e = randn(n,1);
  xnew = A*x + B*e;
  ynew(:,k) = C*x + e;
  x = xnew;  
end

% Add noise

by = ynew + 5e-2*randn(n,T+1);

bx = zeros(m,n*(i+j-1));
for k = 1:j
  bx(:,(k-1)*n+1:k*n) = zeros(n,n);
  for t = 1:T+2-k
    bx(:,(k-1)*n+1:k*n) = bx(:,(k-1)*n+1:k*n) + by(:,t+k-1)*by(:,t)';
  end
end
bx = bx/(T+1);

q=zeros(m,n*(i+j-1));
q(:,1:n*j) = ones(m,n*j);

% save Complete_P6 i j m n bx q

