function X_true = synthdyn(numtracks, numframes)

% A natural coordinate system:
xmax= 5;
ymax = 6;

% Simple dynamics (note, we will reflect around the walls)
A = [1 0.5; 0 1];
A = kron(eye(2), A);
v_x_x = 1e-4 * diag([1e-6 1e0 1e-6 1e0]);

for track_count = 1:numtracks,

    % generate a path according to true dynamics.
    path = [rand*xmax;0;rand*ymax;0];
    for i=2:numframes,
      path(:,i) = A*path(:,i-1) + sqrt(v_x_x)*randn(4,1);
    end
    path([2;4],:) = [];

    % reflect path along the walls
    p = 1;
    while p
      p = 0;
      v=find(path(1,:)<0);
      if(~isempty(v))
            path(1,v(1):end) = -path(1,v(1):end);
            p=1;
      end

      v=find(path(2,:)<0);
      if(~isempty(v))
            path(2,v(1):end) = -path(2,v(1):end);
            p=1;
      end

      v=find(path(1,:)>xmax);
      if(~isempty(v))
            path(1,v(1):end) = 2*xmax-path(1,v(1):end);
            p=1;
      end

      v=find(path(2,:)>ymax);
      if(~isempty(v))
            path(2,v(1):end) = 2*ymax-path(2,v(1):end);
            p=1;
      end
    end

    % smooth path with simple filter.
    g = [1 2 1];
    g=conv(g,g);g=conv(g,g);g=conv(g,g);
    g=g./sum(g);
    
    X_true(:,:,track_count) = [conv2(path(1,:), g,'valid');  conv2(path(2,:), g,'valid');];
end
