order =3 ;
numBr = 2^order - 1;     % number of airways
numOrd1 = (numBr+1)/2;
r_new = NN(:,1:numBr);

for i = 1:numOrd1
[Maxima,MaxIdx] = findpeaks(r_new(:,i));
DataInv = 1.01*max(r_new(:,i)) - r_new(:,i);
[Minima_r,MinIdx] = findpeaks(DataInv);
r1 = r_new(:,i);
Minima_r = r1(MinIdx);

M=round(length(Maxima)/3);
[val1,ind1]=max(Maxima(1:M));
[val2,ind2]=max(Maxima(M+1:end));
ind2=ind2+M;
[val3,ind3]=min(Minima_r(round(M/2):M));

[r_min2,ind4]=max(Minima_r(M+1:end));
ind4=ind4+M;

t_min = t(MinIdx);
t_max = t(MaxIdx);

Pre_stretch_min = Minima_r(20);
Post_stretch_min = Minima_r(22);
Elongation = Post_stretch_min - Pre_stretch_min;

% plot(t_min(22:end),Minima_r(22:end)/Pre_stretch_min,'g*-')
% hold on
plot(t_max(20:end),Maxima(20:end)/Maxima(19),'r')
end