Mercurial > hg > emotion-detection-top-level
comparison Code/Descriptors/Matlab/MPEG7/AudioSpectralFlatness.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 [ASF] = AudioSpectralFlatness(raw, fs, noOfFrames, frameLength) | |
2 | |
3 check this works! | |
4 | |
5 hopSize = frameLength; | |
6 windowsize = frameLength; | |
7 FFTsize = frameLength; | |
8 windowType = hamming(frameLength); | |
9 | |
10 % bin = fs/512; | |
11 % bandsNumber = 24; | |
12 % loEdge = 250; | |
13 % hiEdege = 16000; | |
14 | |
15 | |
16 loEdge = 250; | |
17 hiEdge = 16000; % Setting default hiedge | |
18 | |
19 if (hiEdge >= fs/2) % Check if value for hiedge is valid | |
20 % sr/2-1 : Skipping extraction up to sr/2; Not possible due to 5 percent band overlap | |
21 hiEdge = min(hiEdge,fs/2-1); | |
22 end | |
23 hiEdge = 2^(floor(log2(hiEdge/1000)*4)/4)*1000 ; % Setting exact value for hiEdge, rounding to next lower frequency if necessary | |
24 if (hiEdge*1.05 >= fs/2) | |
25 hiEdge = hiEdge/2^0.25 ; | |
26 end; %Now it's possible to check if hiEdge is valid | |
27 | |
28 N = frameLength; | |
29 | |
30 numbands = floor(4*log2(hiEdge/loEdge)); | |
31 firstband = round(log2(loEdge/1000)*4); | |
32 overlap = 0.05; | |
33 grpsize = 1; | |
34 | |
35 [fftout,phase] = mpeg7getspec( raw, fs, hopSize, windowsize, windowType, FFTsize ); | |
36 band=[]; | |
37 for k = 1:numbands | |
38 f_lo = loEdge * (2^((k-1)/4)) * (1-overlap); | |
39 f_hi = loEdge * (2^((k )/4)) * (1+overlap); | |
40 | |
41 i_lo = round( f_lo/(fs/N) ) + 1; | |
42 i_hi = round( f_hi/(fs/N) ) + 1; | |
43 | |
44 fband(k,1) = f_lo; | |
45 fband(k,2) = f_hi; | |
46 | |
47 iband(k,1) = i_lo; | |
48 iband(k,2) = i_hi; | |
49 | |
50 % Rounding of upper index according due to coefficient grouping | |
51 if (k+firstband-1 >= 0) %Start grouping at 1kHz | |
52 grpsize = 2^ceil( (k+firstband )/4); | |
53 i_hi = round((i_hi-i_lo+1)/grpsize)*grpsize + i_lo-1 ; | |
54 else | |
55 grpsize = 1; | |
56 end | |
57 tmp = fftout(i_lo:i_hi,:) .^ 2; % PSD coefficients | |
58 ncoeffs = i_hi - i_lo + 1; | |
59 | |
60 if (k+firstband-1 >= 0) % Coefficient grouping | |
61 tmp2 = tmp(1:grpsize:ncoeffs,:); | |
62 for g=2:grpsize | |
63 tmp2 = tmp2 + tmp(g:grpsize:ncoeffs,:) ; | |
64 end | |
65 tmp = tmp2; | |
66 end | |
67 % Actual calculation | |
68 ncoeffs = ncoeffs/grpsize ; | |
69 tmp = tmp + 1e-50; % avoid underflow for zero signals | |
70 gm(k,:) = exp( sum(log(tmp))/ncoeffs ); % log processing avoids overflow | |
71 am(k,:) = sum(tmp) / ncoeffs; | |
72 end | |
73 ASF = (gm./am)'; | |
74 | |
75 % myColor = 'rx'; | |
76 % for i=1:(length(raw)/frameLength) | |
77 % subplot(411); plot( raw( (i-1)*frameLength+1 : (i*frameLength) )); | |
78 % subplot(412); plot( fftout(:,i) ); | |
79 % subplot(425); plot( i, ASF(i,1), myColor ); hold on; | |
80 % subplot(426); plot( i, ASF(i,2), myColor ); hold on; | |
81 % subplot(427); plot( i, ASF(i,3), myColor ); hold on; | |
82 % subplot(428); plot( i, ASF(i,4), myColor ); hold on; | |
83 % end | |
84 % lo_edge = loEdge; | |
85 % hi_edge = hiEdge; | |
86 | |
87 % for n = 1:noOfFrames | |
88 % j = (n-1) * 512 + 1; | |
89 % k = n * 512; | |
90 % if(k<=length(raw)) | |
91 % temp = raw(j:k); | |
92 % end | |
93 % if(k>length(raw)) | |
94 % | |
95 % temp = [raw(j:end)' zeros(512-length(raw(j:end)),1)']; | |
96 % end | |
97 % | |
98 % FFTX=fft(temp,hopSize); | |
99 % subplot(311); plot(abs(FFTX(1:length(FFTX)/2))); | |
100 % BW=1.5*fs*1024; | |
101 % PSD=FFTX/BW; | |
102 % | |
103 % for b = 1:24 | |
104 % floKb = 0.95*loEdge * 2^(0.25*b-0.25); | |
105 % fhiKb = 1.05*loEdge * 2^(0.25*b); | |
106 % lowKbp = round( floKb/(fs/512) ) + 1; | |
107 % hiKbp = round( fhiKb/(fs/512) ) + 1; | |
108 % | |
109 % if (b-9 >= 0) | |
110 % groupSize = 2^ceil( (b-8)/4); | |
111 % hiKbp = round((hiKbp-lowKbp+1)/groupSize)*groupSize + lowKbp -1 ; | |
112 % else | |
113 % groupSize = 1; | |
114 % end | |
115 % | |
116 % newtemp = PSD(lowKbp:hiKbp).*conj(PSD(lowKbp:hiKbp)); | |
117 % | |
118 % if (b-9 >= 0) | |
119 % temp1 = newtemp(1:groupSize:(hiKbp-lowKbp+1)) ; | |
120 % for i=2:groupSize | |
121 % temp1 = temp1 + newtemp(i:groupSize:(hiKbp-lowKbp+1)) ; | |
122 % end | |
123 % newtemp = temp1; | |
124 % end | |
125 % GM(b,n) = exp( sum(log(newtemp))/ (hiKbp-lowKbp+1)); | |
126 % AM(b,n) = sum(newtemp) / (hiKbp-lowKbp+1); | |
127 % end | |
128 % ASF = (GM./AM)'; | |
129 % subplot(312); plot(temp);subplot(313); plot(ASF(n,1:6)); | |
130 % end | |
131 | |
132 | |
133 |