Skip to content

Instantly share code, notes, and snippets.

@vanne02135
Created February 11, 2010 21:18
Show Gist options
  • Save vanne02135/301966 to your computer and use it in GitHub Desktop.
Save vanne02135/301966 to your computer and use it in GitHub Desktop.
Matlab function to determine RT60 reverberation time from burst signals. Works at least with 2 of my recorded samples of clapping hands.
function r = rt60(s, Fs)
% rt60 (s, Fs) : determine reverberation time from signal s with sampling
% frequency Fs (44100 Hz for most wav's).
t = (0:(length(s)-1))'/Fs;
dt = 1/Fs;
s2 = abs(s);
s2 = s.^2;
s2db = 10*log10(s2/max(s2));
%
startThreshold = -10;
endThreshold = median(s2db);
s2db = ma(s2db, floor(Fs/2200));
start = 1;
t1 = 1;
t2 = 2;
r = [];
while ~isempty(t1) && ~isempty(t2)
t1 = start + find(s2db(start:end) > startThreshold,1, 'first');
t2 = t1 + find(s2db(t1:end) < endThreshold, 1, 'first');
start = t2;
if (t2-t1)*dt < 0.1
continue
elseif ~isempty(t1) && ~isempty(t2)
myenv = s2db(t1:t2);
tt = ((1:length(myenv))*dt)';
H = [tt ones(length(myenv), 1)];
myenv(isinf(myenv)) = 0; % todo fix this
thta = H\myenv(:);
r = [r, -60 / thta(1)];
%plot(tt, myenv, tt, thta(1)*tt + thta(2))
%pause
end
end
disp(sprintf('Analyzed %d sounds, mean RT60 = %f +/- %f, median RT60 = %f', length(r), mean(r), std(r), median(r)))
function r = ma(s, N)
r = conv(s, ones(N, 1)/N);
r = r(1:length(s));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment