comparison Code/Descriptors/Matlab/MPEG7/calculate_HNR.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [HNR] = calculate_HNR( y, fs, noOfFrames, silenceFrames, pitch )
2
3 %find the maximum lag M
4 DEBUG=0;
5
6 maxPeriod = ceil(fs/getVariables('getMinFreq')); %get the default minimum fundatmental frequency
7 minPeriod = floor(fs/getVariables('getMaxFreq')); %get the default maximum fundamental frequency
8
9 for i = 1:(noOfFrames - 1)
10 if( silenceFrames(i) == 1 )
11
12 % frame is not silent
13 NA = xcorr(y(:,i), y(:,i), 'coeff');
14 NA = NA( ceil(length(NA)/2) : end );
15
16 if(DEBUG)
17 subplot(211); plot(y(:,i)); title(i);
18 subplot(212); plot(NA); hold on;
19 end
20
21 % find the maximum nearset to the predicted pitch
22 f0 = pitch(i);
23 if( (f0 < minPeriod) || (isnan(f0)) )
24 f0 = minPeriod;
25 end
26 % perform a search outwards from that point
27 startSearch = floor(f0-(f0*0.1));
28 endSearch = ceil(f0+(f0*0.1));
29 if( startSearch > length(NA) )
30 startSearch = length(NA) - 20;
31 end
32 if( endSearch > length(NA) )
33 endSearch = length(NA);
34 end
35 [max_value max_position] = max( NA( startSearch : endSearch ));
36
37 if(DEBUG)
38 plot( max_position + startSearch - 1, max_value, 'gx' );
39 plot( startSearch : endSearch, NA(startSearch : endSearch), 'r');
40 hold off;
41 end
42
43 HR(i) = max_value;
44
45 if( HR(i) < 0)
46 % if the sample is negative it probably means the frame is
47 % silent so just set to 'most noisy so far'
48 % if(i>1)
49 % HNR(i) = min( HNR );
50 % else
51 HNR(i) = NaN;
52 % end
53 else
54 HNR(i)= 10*log10(HR(i)/(1-HR(i)));
55 end
56 if(DEBUG) title(HNR(i)); end
57 else
58 HNR(i) = NaN;
59 end
60
61 end
62
63
64
65
66
67
68
69
70