function [amplitudes,times, extremes]=oscilations_linpred2(amplitudes,times, extremes,rr_all,n);
% прогнозирование колебаний по амплитудам и фазам.
amplcoeffs=polyfit(times,amplitudes,1);
ampla=amplcoeffs(2);
amplb=amplcoeffs(1);

rrcoeffs=polyfit(1:length(times),times,1);%(2:length(times)),rr_all,1);
rr_a=rrcoeffs(2);
rr_b=rrcoeffs(1);
%figure;
%plot(times, amplitudes);
%title('amplitudes');
%figure;
%plot(times(2:length(times)), rr_all,'r');
%title('rr');
times=[];%times(1);
amplitudes=[];%amplitudes(1);
extremes_old=extremes;
extremes=[];
for i=1:length(extremes_old)+n
    %next_time=times(length(times));
    next_time=round(rr_a+i*rr_b);
    if (next_time<1)
        next_time=1;
    end
    next_rr=rr_b;
    %next_rr=round(rr_a+rr_b*next_time);
    %next_rr=round(mean(rr_all));
    next_ampl=ampla+amplb*(next_time+next_rr);
    times=[times,next_time];%+next_rr];
    amplitudes=[amplitudes,next_ampl];
    if (isempty(extremes))
        extremes=extremes_old(1);
    else
        extremes=[extremes,-extremes(length(extremes))];
    end
    rr_all=[rr_all,next_rr];
end
a=3;
%figure;
%plot(times, amplitudes);
%hold on;
%plot(times(2:length(times)), rr_all,'r');
%title('after');

