Mercurial > hg > emotion-detection-top-level
comparison Code/Descriptors/Matlab/Common/findMaxima.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 [Maxima, countMaxima] = findMaxima(f, step) | |
2 | |
3 % | |
4 % MAXIMA ESTIMATION | |
5 % | |
6 % function [Maxima, countMaxima] = findMaxima(f, step); | |
7 % | |
8 % This function estimates the local maxima of a sequence | |
9 % | |
10 % ARGUMENTS: | |
11 % f: the input sequence | |
12 % step: the size of the "search" window | |
13 % | |
14 % RETURN: | |
15 % Maxima: [2xcountMaxima] matrix containing: | |
16 % 1. the maxima's indeces | |
17 % 2. tha maxima's values | |
18 % countMaxima: the number of maxima | |
19 % | |
20 | |
21 | |
22 | |
23 % | |
24 % STEP 1: find maxima: | |
25 % | |
26 | |
27 countMaxima = 0; | |
28 for (i=1:length(f)-step-1) % for each element of the sequence: | |
29 if (i>step) | |
30 if (( mean(f(i-step:i-1))< f(i)) && ( mean(f(i+1:i+step))< f(i))) | |
31 % IF the current element is larger than its neighbors (2*step window) | |
32 % --> keep maximum: | |
33 countMaxima = countMaxima + 1; | |
34 Maxima(1,countMaxima) = i; | |
35 Maxima(2,countMaxima) = f(i); | |
36 end | |
37 else | |
38 if (( mean(f(1:i))<= f(i)) && ( mean(f(i+1:i+step))< f(i))) | |
39 % IF the current element is larger than its neighbors (2*step window) | |
40 % --> keep maximum: | |
41 countMaxima = countMaxima + 1; | |
42 Maxima(1,countMaxima) = i; | |
43 Maxima(2,countMaxima) = f(i); | |
44 end | |
45 | |
46 end | |
47 end | |
48 | |
49 % | |
50 % STEP 2: post process maxima: | |
51 % | |
52 | |
53 MaximaNew = []; | |
54 countNewMaxima = 0; | |
55 i = 0; | |
56 while (i<countMaxima) | |
57 % get current maximum: | |
58 i = i + 1; | |
59 curMaxima = Maxima(1,i); | |
60 curMavVal = Maxima(2,i); | |
61 | |
62 tempMax = Maxima(1,i); | |
63 tempVals = Maxima(2,i); | |
64 | |
65 % search for "neighbourh maxima": | |
66 while ((i<countMaxima) && ( Maxima(1,i+1) - tempMax(end) < step / 2)) | |
67 i = i + 1; | |
68 tempMax(end+1) = Maxima(1,i); | |
69 tempVals(end+1) = Maxima(2,i); | |
70 end | |
71 | |
72 | |
73 % find the maximum value and index from the tempVals array: | |
74 %MI = findCentroid(tempMax, tempVals); MM = tempVals(MI); | |
75 | |
76 [MM, MI] = max(tempVals); | |
77 | |
78 if (MM>0.02*mean(f)) % if the current maximum is "large" enough: | |
79 countNewMaxima = countNewMaxima + 1; % add maxima | |
80 % keep the maximum of all maxima in the region: | |
81 MaximaNew(1,countNewMaxima) = tempMax(MI); | |
82 MaximaNew(2,countNewMaxima) = f(MaximaNew(1,countNewMaxima)); | |
83 end | |
84 tempMax = []; | |
85 tempVals = []; | |
86 end | |
87 | |
88 Maxima = MaximaNew; | |
89 countMaxima = countNewMaxima; | |
90 | |
91 |