% Execute Data_analysis before this code in order to get VoR and VcR


Tw_range = (1:frs)/30;   % frs is the number of the grams that is valid (not NaN
Vo_data = OriV(1:frs);


ft = fittype( 'Vfit(A, k, err, v, x)');    % x = window length 


f_strucVo = fit(Tw_range',Vo_data', ft,'StartPoint', [0.3, 5, 5, 100], 'Upper', U_mat, 'Lower', L_mat, 'maxiter',10000);


% plot([0 1], [f_strucVo.v f_strucVo.v]) 
% hold on
% scatter(Tw_range, Vo_data)
% plot(1/30:0.01:1, f_strucVo(1/30:0.01:1))


Vo_fit = f_strucVo.v;

P_Vo = 0 ;
pltd = Vo_data(3:12); % Plateau detection
if max(pltd)-min(pltd)< mean(pltd)*0.05
    Vo_fit = mean(pltd);
    P_Vo = 1;
end



Vc_data = CurV(1:frs);
f_strucVc = fit(Tw_range',Vc_data', ft,'StartPoint', [0.3, 5, 5, 100], 'Upper', U_mat, 'Lower', L_mat, 'maxiter',10000);
Vc_fit = f_strucVc.v;

P_Vc = 0 ;

pltd = Vc_data(3:12); % Plateau detection
if max(pltd)-min(pltd)< mean(pltd)*0.05
    Vc_fit = mean(pltd);
    P_Vc = 1;
end




