%% Reconstruct Data using Phase Space Reconstruction
% In this example, assume that you have measurements for a Lorenz Attractor. Your measurements are along the x direction only, but the attractor is a three-dimensional system. Using this limited data, reconstruct the phase space such that the properties of the original system are preserved.
% Load the Lorenz Attractor data and visualize its x, y and z measurements on a 3-D plot.

load('lorenzAttractorExampleData.mat','data');
plot3(data(:,1),data(:,2),data(:,3));

%
% Estimate the lag and dimension using the x-direction measurement.

xdata = data(:,1);
[~,eLag,eDim] = phaseSpaceReconstruction(xdata)

% Since the Lorenz Attractor has data in 3 dimensions, the estimated embedding dimension eDim is 3.
%
% Visualize the reconstructed phase space using the estimated lag and embedding dimension.

phaseSpaceReconstruction(xdata,eLag,eDim);

% As observed from the 3x3 phase space plot, the topology of the attractor is recovered. x_1 \left(t+10\right) and x_1 \left(t+20\right) are the other two states reconstructed with the estimated lag value of 10. The diagonal plots (1,1), (2,2) and (3,3) represent the histogram of x_1 \left(t\right), x_1 \left(t+10\right)and x_1 \left(t+20\right)data, respectively.
% Copyright 2018 The MathWorks, Inc.