clear

%% parameter values

% system parameters
c1=0.1;
c3cr=40*c1/9;

num_sampl=1000;
c3=linspace(c3cr*0.7,c3cr*1.3,num_sampl);

% range of initial conditions for x0 and x0d
x0_range=[0.7, 2];
xd0_range=[0.7, 2];

% time span and time interval
tfinal=800;
t_steps=1000;
tspan=linspace(0,tfinal,t_steps);

%% generate random initial conditions

x0(:,1)=rand(num_sampl,1)*(x0_range(2)-x0_range(1))+x0_range(1);
x0(:,2)=rand(num_sampl,1)*(xd0_range(2)-xd0_range(1))+xd0_range(1);


%% perform simulations
options = odeset('RelTol', 1e-6, 'AbsTol', 1e-8);
x=cell(length(c3),1);
for i=1:num_sampl
    [~, x{i}] = ode45 (@(t, xt) system_NLD(t, xt, [c1, c3(i)]), tspan, x0(i,:), options);
end

%% save data
clear("i");
% save NLD_4incremental_testing_raw_simulation_data_c1_01_tfinal_800.mat

%% normalize data polar_01_log_mvm

rho=cell(length(x),1);
for i=1:length(x)
    polar_pure=sqrt(x{i}(:,1).^2+x{i}(:,2).^2);
    max_pol=max(polar_pure);
    polar_01=polar_pure/max_pol;
    polar_01_log=log(polar_01);
    for j=20:length(polar_01_log)
        if max([polar_01_log(j-19):polar_01_log(j)])<-14
            polar_01_log=polar_01_log(1:j);
            break
        end
    end
    polar_01_log_resumpled=spline(linspace(1,length(polar_01_log),length(polar_01_log)), polar_01_log, linspace(1,length(polar_01_log),1000));
    rho{i}=movmean(polar_01_log_resumpled,round(length(polar_01_log_resumpled)/20));
end

%% normalize data polar_01_log_mvm_01

% rho=cell(length(x),1);
% for i=1:length(x)
%     polar_pure=sqrt(x{i}(:,1).^2+x{i}(:,2).^2);
%     max_pol=max(polar_pure);
%     polar_01=polar_pure/max_pol;
%     polar_01_log=log(polar_01);
%     polar_log_01_mvm_=transpose(movmean(polar_01_log,round(length(polar_01_log)/10)));
%     rho{i}=
% end

%% save normalized data
clear("x");
clear("i");
% save NLD_4training_polar_01_log_mvm_c1_05.mat
save NLD_4incremental_testing_polar_01_log_mvm_c1_01.mat






















