%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Embed Lorenz equation data

clear all
close all

%% lorenz_periodic.mat and lorenz_chaotic.mat
%% hold x and t time series
%% produced using test_lorenz.m
%  b = 8/3, sigma = 10, r = 23.9653125
%% and b = 8/3, \sigma = 10, r = 23.965250
filenames=char('lorenz_periodic','lorenz_chaotic');

for ii=1:2
    eval(['load ' deblank(filenames(ii,:)) '.mat'])
    interp_t=linspace(min(t),max(t),7000)';
    dt=interp_t(2)-interp_t(1);
    
    %interpolate theta to a finer time step 
    interp_x=interp1(t,x,interp_t,'spline');
    
    %embedding
    numbins=100;
    
    tau = modified_estimateTauAMI(numbins, interp_x, 0);
    %d_e = FNN(omega,tau);
    d_e=3;
    
    n        = floor(length(interp_x)/tau)*tau;
    embedded = zeros(n-(d_e-1)*tau,d_e);
    for k=1:d_e
        embedded(:,k) = interp_x((k-1)*tau+1:n-(d_e-k)*tau);
    end
    
    figure(ii)
    plot3(embedded(:,1),embedded(:,2),embedded(:,3))
    title(strcat('Delay Coordinate Embedding; d_{E} = ', int2str(d_e), '; \tau = ', num2str(tau*dt),' s'));
    xlabel('\omega_{t}');
    ylabel(strcat('\omega_{t+\tau}'));
    zlabel(strcat('\omega_{t+2\tau}'));
    
end