function delta_I_threshold = Event_STD_Construction(data,level_pts)

number_of_levels=length(level_pts)-1;
std_list=zeros(number_of_levels,1);

for i=1:number_of_levels
    
    I_array=data(level_pts(i):level_pts(i+1));
    sub_event_size=length(I_array);
    ipt=findchangepts(I_array,'MaxNumChanges',2);

    if isempty(ipt)==0
        ipt=sort(unique([1;ipt(1);ipt(end)-1;sub_event_size]));
        true_levels=length(ipt)-1;
        lvl_length=zeros(true_levels,1);
            for j=1:true_levels
                lvl_length(j)=ipt(j+1)-ipt(j);
            end

        [~,I]=max(lvl_length);
        lvl_data=I_array(ipt(I):ipt(I+1));
        std_list(i)=std(lvl_data);
    else
        lvl_data=I_array;
        std_list(i)=std(lvl_data);
    end

end
    delta_I_threshold=3*mean(std_list);
end

