-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputeLoudnessRMS.m
More file actions
36 lines (33 loc) · 1.12 KB
/
computeLoudnessRMS.m
File metadata and controls
36 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [snrVoice, rmsVoice, rmsBase] = computeLoudnessRMS(Audio, Afs, lat, dur, commandT)
%Loudness comparison between baseline and speech
pb=0;
if pb
figure;
plot(Audio, 'k');
end
nTrials = length(lat);
rmsVoice = NaN*zeros(nTrials,1);
rmsBase = NaN*zeros(nTrials,1);
for tr = 1:nTrials
baselineStart = round((commandT(tr)-0.5)*Afs);
baselineEnd = round(commandT(tr)*Afs);
spStart = round((commandT(tr)+lat(tr))*Afs);
spEnd = round((commandT(tr)+lat(tr)+dur(tr))*Afs);
if ~isnan(spStart) && ~isnan(spEnd)
rmsVoice(tr) = rms(Audio(spStart:spEnd));
else
rmsVoice(tr) = nan;
end
rmsBase(tr) = rms(Audio(baselineStart:baselineEnd));
% if ~sum(tr == trials.BaseRejectNoise) %check to see that we haven't noise rejected trial
% rmsBase(tr) = rms(Audio(baselineStart:baselineEnd));
% else
% rmsBase(tr) = NaN;
% end
if pb && ~isnan(spEnd) && ~isnan(spStart)
hold on;
plot(baselineStart:baselineEnd, Audio(baselineStart:baselineEnd), 'b');
plot(spStart:spEnd, Audio(spStart:spEnd), 'r');
end
end
snrVoice = rmsVoice./rmsBase;