% idea is to find Lyapunov exponents for the time series data
%

% reference: J. Zhang and K. Man, "Time series prediction using Lyapunov
% exponents in embedding phase space," Proceedings of ICSP, 1998, 
% pp. 221-224.

% ========================================================================
% The matlab code for Chaos Theory - 
%                 Nonlinear Statistical Modeling of Speech
% date : July 15, 2005 Friday.
% IES: http://www.cavs.msstate.edu/hse/ies/projects/nsf_nonlinear
%
% ========================================================================
% ========================================================================
%         
%       Lyapunov exponents : its estimation and utility for prediction
%       
% ========================================================================

% setting up the environment
% clearing all the variables, clearing the command window, closing all the
% figures (plots)
%
clear all;
clc;
close all;


% using logistic equation for the prediction
% x(t+1) = A * x(t) * ( 1 - x(t))
%
% generate a time series data
%
numOfSamples = 512; % total number of samples
x(1) = 0.36; % the starting value
growth_factor = 4.0; % rate at which the population iterates

for i = 2:1:512
    x(i) = growth_factor * x(i-1) * ( 1 - x(i-1));
end;

% plotting the time series data
%
figure;
plot(x);
title('logistic equation - chaotic time series');
xlabel('Time series data number');
ylabel(' Time series data');
xlim([0 600]); ylim([0 1]);
grid on;

% state space in two dimensions
figure;
xdata2D = x(:,1:1:511);
ydata2D = x(:,2:1:512);
for i = 1:1:size(xdata2D,2)
    plot(xdata2D(i), ydata2D(i));
    hold on;
end;
title('Logistic Equation - state space in 2 Dimensions');
xlabel('x(t)'); ylabel(' x(t+1)');
grid on;


% state space in three dimensions
%
figure;
xdata3D = x(:,1:1:510);
ydata3D = x(:,2:1:511);
zdata3D = x(:,3:1:512);
for i = 1:1:size(xdata3D,2)
    plot3(xdata3D(i), ydata3D(i), zdata3D(i));
    hold on;
end;
title('Logistic Equation - state space in 3 Dimensions');
xlabel('x(t)'); ylabel(' x(t+1)'); zlabel('x(t+2)');
grid on;





