function [schroeder_log, EDT, RT20] = RT_backward( impulse, kgrid)
%ANALYSE slope to determine -60dB sample
fs=1/kgrid.dt;
Tfast=0.075; %[s]
Nfast=Tfast*fs; %[samples]
decay=abs(impulse);

%for k=1:1:floor(length(decay)/Nfast);
%avrg_decay_Nfast=sum(decay(1,(k-1)*Nfast+1:Nfast*k))/Nfast;
%avrg_decay(1,(k-1)*Nfast+1:Nfast*k)=avrg_decay_Nfast;
%end

avrg_decay(length(decay):-1:1) = cumsum(decay(length(decay):-1:1));
decay_log = 20 * log10(avrg_decay/max(avrg_decay));

end_decay=max(find(decay_log > -30 ));
IMPULS_abs =  abs(impulse(1,1:end_decay));

% BACKWARD INTEGRATION
decay_curve(length(IMPULS_abs):-1:1) = cumsum(IMPULS_abs(length(IMPULS_abs):-1:1));
schroeder_log = 20 * log10(decay_curve/max(decay_curve));

% EDT COMPUTING
decay_start=max(find(schroeder_log>-1 ));
decay_end=max(find(schroeder_log> -11));
decay_interval=schroeder_log(1,decay_start:decay_end);

t=length(decay_interval)/fs*1000; %[ms]
time=linspace(0,t,length(decay_interval));
linearCoefficients = polyfit(time, decay_interval, 1);
EDT=-60/linearCoefficients(1,1); %[ms]

% RT20 COMPUTING
decay_start=max(find(schroeder_log > -5));
decay_end=max(find(schroeder_log> -25));
decay_interval=schroeder_log(1,decay_start:decay_end);

t=length(decay_interval)/fs*1000; %[ms]
time=linspace(0,t,length(decay_interval));
linearCoefficients = polyfit(time, decay_interval, 1);
RT20=-60/linearCoefficients(1,1); %[ms]

% RT30 COMPUTING
%decay_start=max(find(schroeder_log > -5));
%decay_end=max(find(schroeder_log> -35));
%decay_interval=schroeder_log(1,decay_start:decay_end);

%t=length(decay_interval)/fs*1000; %[ms]
%time=linspace(0,t,length(decay_interval));
%linearCoefficients = polyfit(time, decay_interval, 1);
%RT30=-60/linearCoefficients(1,1); %[ms]
end

