function [last_peak_value0,last_peak_value1,last_peak_value2,avglastpeek,maxlastpeek]=get_last_peek_value(Y_w,times, extrems);
% находит высоту двух последних пиков
N=length(Y_w);
current_times=find(times<N);
last_cur_time=max(current_times);
last_maxs=find(extrems(1:last_cur_time)>0);
nmaxs=length(last_maxs);
last_peak_num=last_maxs(nmaxs);
last_peak_value2=Y_w(times(last_peak_num));
if (nmaxs>1) % 20111004
    last_peak_num2=last_maxs(nmaxs-1);
else
    last_peak_num2=last_maxs(1);
end
if (nmaxs>2) % 20111004
    last_peak_num0=last_maxs(nmaxs-2);
else
    last_peak_num0=last_maxs(1);
end
last_peak_value1=Y_w(times(last_peak_num2));
last_peak_value0=Y_w(times(last_peak_num0));
maspeeks=[];
if (nmaxs>1)
    for imax=last_maxs(1:nmaxs)
        maspeeks=[maspeeks,Y_w(times(imax))];
    end
    avglastpeek=mean(maspeeks);
    maxlastpeek=max(maspeeks);
else
    maspeeks=[];
    avglastpeek=0;
    maxlastpeek=[]; %20111004
end



