%% Initialization and Parameters
% Sequence = [initial SS, step, long SS, short ramp, short SS, long ramp,
% long SS]

% ylim [5 10]
Time = [30,5,40,20,30,40,40];
Time_cum = [Time(1)];
for i = 2:size(Time,2)
    Time_cum(i) = Time_cum(i-1) + Time(i);
end
Value = [5.5,8.5,7.5,7.0];

% Noise magnitude (Gaussian)
noise_mean = 0; noise_var = 0.1^2;

%% Synthesize segments and Combine
initialSS = Value(1)*ones(1,Time(1));

t_step = (Time(1) + 1):(Time(1) + Time(2));
STEPA = [Time(1), 1; Time(1)+Time(2), 1];
STEPB = [Value(1); Value(2)];
STEPC = STEPA\STEPB;
step = STEPC(1)*t_step + STEPC(2);

longSS = Value(2)*ones(1,Time(3));

t_sramp = (Time(1) + Time(2) + Time(3) + 1):(Time(1) + Time(2) + Time(3) + Time(4));
SRAMPA = [(Time(1) + Time(2) + Time(3)), 1; (Time(1) + Time(2) + Time(3) + Time(4)), 1];
SRAMPB = [Value(2); Value(3)];
SRAMPC = SRAMPA\SRAMPB;
sramp = SRAMPC(1)*t_sramp + SRAMPC(2);
%sramp = exp(-(t_sramp - t_sramp(1))/2)-1 + step(end);

shortSS = Value(3)*ones(1,Time(5));

t_lramp = (SRAMPA(2,1) + Time(5) + 1):(SRAMPA(2,1) + Time(5) + Time(6));
LRAMPA = [(t_lramp(1)-1), 1; (t_lramp(end)), 1];
LRAMPB = [Value(3); Value(4)];
LRAMPC = LRAMPA\LRAMPB;
lramp = LRAMPC(1)*t_lramp + LRAMPC(2);

halfSS = Value(4)*ones(1,Time(7));

sequence1 = [initialSS,step,longSS,sramp,shortSS,lramp,halfSS];
sequence2 = flip(sequence1);
sequence = [sequence1 sequence2];
sequence_ori = sequence;

% Pdf
%pdS = makedist('Stable','alpha',1.5,'beta',0,'gam',0.0725,'delta',0);
%noise = random(pdS,size(sequence,2),1)';
%sequence = sequence + noise;
%sequence = sequence + sqrt(noise_var)*randn(size(sequence)) + noise_mean;
noise_s = sqrt(noise_var)*randn(size(sequence,2),1) + noise_mean;
noise_cor = [noise_s(1)];
noise = noise_s(1);
for i = 2:size(noise_s,1)
     noise = 0.9*noise_s(i)+ 0.1*noise;
     noise_cor = [noise_cor, noise];
 end
sequence = sequence + noise_cor;

time = 1:size(sequence,2);

plot(time,sequence)
ylim([5 10])
%% Standard
standard1 = [ones(1,Time(1)), zeros(1,Time(2)), ones(1,Time(3)), zeros(1,Time(4)), ones(1,Time(5)), zeros(1,Time(6)), ones(1,Time(7))];  % 1 means SS, 0 means TS
standard2 = flip(standard1);
standard = [standard1, standard2];
save scenario_colored sequence sequence_ori standard Time_cum
