Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@miremotion/miremotion.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function varargout = miremotion(orig,varargin) | |
2 % Predicts emotion along three dimensions and five basic concepts. | |
3 % Optional parameters: | |
4 % miremotion(...,'Dimensions',0) excludes all three dimensions. | |
5 % miremotion(...,'Dimensions',3) includes all three dimensions (default). | |
6 % miremotion(...,'Activity') includes the 'Activity' dimension. | |
7 % miremotion(...,'Valence') includes the 'Valence' dimension. | |
8 % miremotion(...,'Tension') includes the 'Tension' dimension. | |
9 % miremotion(...,'Dimensions',2) includes 'Activity' and 'Valence'. | |
10 % miremotion(...,'Arousal') includes 'Activity' and 'Tension'. | |
11 % miremotion(...,'Concepts',0) excludes all five concepts. | |
12 % miremotion(...,'Concepts') includes all five concepts (default). | |
13 % miremotion(...,'Happy') includes the 'Happy' concept. | |
14 % miremotion(...,'Sad') includes the 'Sad' concept. | |
15 % miremotion(...,'Tender') includes the 'Tender' concept. | |
16 % miremotion(...,'Anger') includes the 'Anger' concept. | |
17 % miremotion(...,'Fear') includes the 'Fear' concept. | |
18 % miremotion(...,'Frame',...) predict emotion frame by frame. | |
19 % | |
20 % Selection of features and coefficients are taken from a study: | |
21 % Eerola, T., Lartillot, O., and Toiviainen, P. | |
22 % (2009). Prediction of multidimensional emotional ratings in | |
23 % music from audio using multivariate regression models. | |
24 % In Proceedings of 10th International Conference on Music Information Retrieval | |
25 % (ISMIR 2009), pages 621-626. | |
26 % | |
27 % The implemented models are based on multiple linear regression with 5 best | |
28 % predictors (MLR option in the paper). The box-cox transformations have now been | |
29 % removed until the normalization values have been established with a large sample of music. | |
30 % | |
31 % TODO: Revision of coefficients to (a) force the output range between 0 - 1 and | |
32 % (b) to be based on alternative models and materials (training sets). | |
33 % | |
34 % Updated 03.05.2010 TE | |
35 % | |
36 frame.key = 'Frame'; | |
37 frame.type = 'Integer'; | |
38 frame.number = 2; | |
39 frame.default = [0 0]; | |
40 frame.keydefault = [1 1]; | |
41 option.frame = frame; | |
42 | |
43 dim.key = 'Dimensions'; | |
44 dim.type = 'Integer'; | |
45 dim.default = NaN; | |
46 dim.keydefault = 3; | |
47 option.dim = dim; | |
48 | |
49 activity.key = 'Activity'; | |
50 activity.type = 'Boolean'; | |
51 activity.default = NaN; | |
52 option.activity = activity; | |
53 | |
54 valence.key = 'Valence'; | |
55 valence.type = 'Boolean'; | |
56 valence.default = NaN; | |
57 option.valence = valence; | |
58 | |
59 tension.key = 'Tension'; | |
60 tension.type = 'Boolean'; | |
61 tension.default = NaN; | |
62 option.tension = tension; | |
63 | |
64 arousal.key = 'Arousal'; | |
65 arousal.type = 'Boolean'; | |
66 arousal.default = NaN; | |
67 option.arousal = arousal; | |
68 | |
69 concepts.key = 'Concepts'; | |
70 concepts.type = 'Boolean'; | |
71 concepts.default = NaN; | |
72 option.concepts = concepts; | |
73 | |
74 happy.key = 'Happy'; | |
75 happy.type = 'Boolean'; | |
76 happy.default = NaN; | |
77 option.happy = happy; | |
78 | |
79 sad.key = 'Sad'; | |
80 sad.type = 'Boolean'; | |
81 sad.default = NaN; | |
82 option.sad = sad; | |
83 | |
84 tender.key = 'Tender'; | |
85 tender.type = 'Boolean'; | |
86 tender.default = NaN; | |
87 option.tender = tender; | |
88 | |
89 anger.key = 'Anger'; | |
90 anger.type = 'Boolean'; | |
91 anger.default = NaN; | |
92 option.anger = anger; | |
93 | |
94 fear.key = 'Fear'; | |
95 fear.type = 'Boolean'; | |
96 fear.default = NaN; | |
97 option.fear = fear; | |
98 | |
99 specif.option = option; | |
100 specif.defaultframelength = 1; | |
101 %specif.defaultframehop = .5; | |
102 | |
103 specif.combinechunk = {'Average',@nothing}; | |
104 specif.extensive = 1; | |
105 | |
106 varargout = mirfunction(@miremotion,orig,varargin,nargout,specif,@init,@main); | |
107 | |
108 | |
109 %% | |
110 function [x type] = init(x,option) | |
111 | |
112 option = process(option); | |
113 | |
114 if option.frame.length.val | |
115 hop = option.frame.hop.val; | |
116 if strcmpi(option.frame.hop.unit,'Hz') | |
117 hop = 1/hop; | |
118 option.frame.hop.unit = 's'; | |
119 end | |
120 if strcmpi(option.frame.hop.unit,'s') | |
121 hop = hop*get(x,'Sampling'); | |
122 end | |
123 if strcmpi(option.frame.hop.unit,'%') | |
124 hop = hop/100; | |
125 option.frame.hop.unit = '/1'; | |
126 end | |
127 if strcmpi(option.frame.hop.unit,'/1') | |
128 hop = hop*option.frame.length.val; | |
129 end | |
130 frames = 0:hop:1000000; | |
131 x = mirsegment(x,[frames;frames+option.frame.length.val]); | |
132 elseif isa(x,'mirdesign') | |
133 x = set(x,'NoChunk',1); | |
134 end | |
135 rm = mirrms(x,'Frame',.046,.5); | |
136 | |
137 le = 0; %mirlowenergy(rm,'ASR'); | |
138 | |
139 o = mironsets(x,'Filterbank',15,'Contrast',0.1); | |
140 at = mirattacktime(o); | |
141 as = 0; %mirattackslope(o); | |
142 ed = 0; %mireventdensity(o,'Option1'); | |
143 | |
144 fl = mirfluctuation(x,'Summary'); | |
145 fp = mirpeaks(fl,'Total',1); | |
146 fc = 0; %mircentroid(fl); | |
147 | |
148 tp = 0; %mirtempo(x,'Frame',2,.5,'Autocor','Spectrum'); | |
149 pc = mirpulseclarity(x,'Frame',2,.5); %%%%%%%%%%% Why 'Frame'?? | |
150 | |
151 s = mirspectrum(x,'Frame',.046,.5); | |
152 sc = mircentroid(s); | |
153 ss = mirspread(s); | |
154 sr = mirroughness(s); | |
155 | |
156 %ps = mirpitch(x,'Frame',.046,.5,'Tolonen'); | |
157 | |
158 c = mirchromagram(x,'Frame','Wrap',0,'Pitch',0); %%%%%%%%%%%%%%%%%%%% Previous frame size was too small. | |
159 cp = mirpeaks(c,'Total',1); | |
160 ps = 0;%cp; | |
161 ks = mirkeystrength(c); | |
162 [k kc] = mirkey(ks); | |
163 mo = mirmode(ks); | |
164 hc = mirhcdf(c); | |
165 | |
166 se = mirentropy(mirspectrum(x,'Collapsed','Min',40,'Smooth',70,'Frame',1.5,.5)); %%%%%%%%% Why 'Frame'?? | |
167 | |
168 ns = mirnovelty(mirspectrum(x,'Frame',.1,.5,'Max',5000),'Normal',0); | |
169 nt = mirnovelty(mirchromagram(x,'Frame',.2,.25),'Normal',0); %%%%%%%%%%%%%%%%%%%% Previous frame size was too small. | |
170 nr = mirnovelty(mirchromagram(x,'Frame',.2,.25,'Wrap',0),'Normal',0); %%%%%%%%%%%%%%%%%%%% Previous frame size was too small. | |
171 | |
172 | |
173 | |
174 x = {rm,le, at,as,ed, fp,fc, tp,pc, sc,ss,sr, ps, cp,kc,mo,hc, se, ns,nt,nr}; | |
175 | |
176 type = {'miremotion','mirscalar','mirscalar',... | |
177 'mirscalar','mirscalar','mirscalar',... | |
178 'mirspectrum','mirscalar',... | |
179 'mirscalar','mirscalar',... | |
180 'mirscalar','mirscalar','mirscalar',... | |
181 'mirscalar',... | |
182 'mirchromagram','mirscalar','mirscalar','mirscalar',... | |
183 'mirscalar',... | |
184 'mirscalar','mirscalar','mirscalar'}; | |
185 | |
186 | |
187 %% | |
188 function e = main(x,option,postoption) | |
189 | |
190 warning('WARNING IN MIRENOTION: The current model of miremotion is not correctly calibrated with this version of MIRtoolbox (but with version 1.3 only).'); | |
191 | |
192 option = process(option); | |
193 rm = get(x{1},'Data'); | |
194 %le = get(x{2},'Data'); | |
195 at = get(x{3},'Data'); | |
196 %as = get(x{4},'Data'); | |
197 %ed = get(x{5},'Data'); | |
198 %fpp = get(x{6},'PeakPosUnit'); | |
199 fpv = get(x{6},'PeakVal'); | |
200 %fc = get(x{7},'Data'); | |
201 %tp = get(x{8},'Data'); | |
202 pc = get(x{9},'Data'); | |
203 sc = get(x{10},'Data'); | |
204 ss = get(x{11},'Data'); | |
205 rg = get(x{12},'Data'); | |
206 %ps = get(x{13},'PeakPosUnit'); | |
207 cp = get(x{14},'PeakPosUnit'); | |
208 kc = get(x{15},'Data'); | |
209 mo = get(x{16},'Data'); | |
210 hc = get(x{17},'Data'); | |
211 se = get(x{18},'Data'); | |
212 ns = get(x{19},'Data'); | |
213 nt = get(x{20},'Data'); | |
214 nr = get(x{21},'Data'); | |
215 | |
216 | |
217 e.dim = {}; | |
218 e.dimdata = mircompute(@initialise,rm); | |
219 if option.activity == 1 | |
220 [e.dimdata e.activity_fact] = mircompute(@activity,e.dimdata,rm,fpv,sc,ss,se); | |
221 e.dim = [e.dim,'Activity']; | |
222 else | |
223 e.activity_fact = NaN; | |
224 end | |
225 if option.valence == 1 | |
226 [e.dimdata e.valence_fact] = mircompute(@valence,e.dimdata,rm,fpv,kc,mo,ns); | |
227 e.dim = [e.dim,'Valence']; | |
228 else | |
229 e.valence_fact = NaN; | |
230 end | |
231 if option.tension == 1 | |
232 [e.dimdata e.tension_fact] = mircompute(@tension,e.dimdata,rm,fpv,kc,hc,nr); | |
233 e.dim = [e.dim,'Tension']; | |
234 else | |
235 e.tension_fact = NaN; | |
236 end | |
237 | |
238 e.class = {}; | |
239 e.classdata = mircompute(@initialise,rm); | |
240 if option.happy == 1 | |
241 [e.classdata e.happy_fact] = mircompute(@happy,e.classdata,fpv,ss,cp,kc,mo); | |
242 e.class = [e.class,'Happy']; | |
243 else | |
244 e.happy_fact = NaN; | |
245 end | |
246 if option.sad == 1 | |
247 [e.classdata e.sad_fact] = mircompute(@sad,e.classdata,ss,cp,mo,hc,nt); | |
248 e.class = [e.class,'Sad']; | |
249 else | |
250 e.sad_fact = NaN; | |
251 end | |
252 if option.tender == 1 | |
253 [e.classdata e.tender_fact] = mircompute(@tender,e.classdata,sc,rg,kc,hc,ns); | |
254 e.class = [e.class,'Tender']; | |
255 else | |
256 e.tender_fact = NaN; | |
257 end | |
258 if option.anger == 1 | |
259 [e.classdata e.anger_fact] = mircompute(@anger,e.classdata,rg,kc,se,nr); | |
260 e.class = [e.class,'Anger']; | |
261 else | |
262 e.anger_fact = NaN; | |
263 end | |
264 if option.fear == 1 | |
265 [e.classdata e.fear_fact] = mircompute(@fear,e.classdata,rm,at,fpv,kc,mo); | |
266 e.class = [e.class,'Fear']; | |
267 else | |
268 e.fear_fact = NaN; | |
269 end | |
270 | |
271 e = class(e,'miremotion',mirdata(x{1})); | |
272 e = purgedata(e); | |
273 fp = mircompute(@noframe,get(x{1},'FramePos')); | |
274 e = set(e,'Title','Emotion','Abs','emotions','Ord','magnitude','FramePos',fp); | |
275 | |
276 %% | |
277 function option = process(option) | |
278 if option.arousal==1 | |
279 option.activity = 1; | |
280 option.tension = 1; | |
281 if isnan(option.dim) | |
282 option.dim = 0; | |
283 end | |
284 end | |
285 if option.activity==1 || option.valence==1 || option.tension==1 | |
286 if isnan(option.activity) | |
287 option.activity = 0; | |
288 end | |
289 if isnan(option.valence) | |
290 option.valence = 0; | |
291 end | |
292 if isnan(option.tension) | |
293 option.tension = 0; | |
294 end | |
295 if isnan(option.concepts) | |
296 option.concepts = 0; | |
297 end | |
298 end | |
299 if not(isnan(option.dim)) && option.dim | |
300 if isnan(option.concepts) | |
301 option.concepts = 0; | |
302 end | |
303 end | |
304 if not(isnan(option.concepts)) && option.concepts | |
305 if isnan(option.dim) | |
306 option.dim = 0; | |
307 end | |
308 end | |
309 if not(isnan(option.dim)) | |
310 switch option.dim | |
311 case 0 | |
312 if isnan(option.activity) | |
313 option.activity = 0; | |
314 end | |
315 if isnan(option.valence) | |
316 option.valence = 0; | |
317 end | |
318 if isnan(option.tension) | |
319 option.tension = 0; | |
320 end | |
321 case 2 | |
322 option.activity = 1; | |
323 option.valence = 1; | |
324 if isnan(option.tension) | |
325 option.tension = 0; | |
326 end | |
327 case 3 | |
328 option.activity = 1; | |
329 option.valence = 1; | |
330 option.tension = 1; | |
331 end | |
332 end | |
333 if isnan(option.activity) | |
334 option.activity = 1; | |
335 end | |
336 if isnan(option.valence) | |
337 option.valence = 1; | |
338 end | |
339 if isnan(option.tension) | |
340 option.tension = 1; | |
341 end | |
342 if isnan(option.concepts) | |
343 option.concepts = 1; | |
344 end | |
345 if option.concepts | |
346 option.happy = 1; | |
347 option.sad = 1; | |
348 option.tender = 1; | |
349 option.anger = 1; | |
350 option.fear = 1; | |
351 end | |
352 if option.happy==1 || option.sad==1 || option.tender==1 ... | |
353 || option.anger==1 || option.fear==1 | |
354 if isnan(option.happy) | |
355 option.happy = 0; | |
356 end | |
357 if isnan(option.sad) | |
358 option.sad = 0; | |
359 end | |
360 if isnan(option.tender) | |
361 option.tender = 0; | |
362 end | |
363 if isnan(option.anger) | |
364 option.anger = 0; | |
365 end | |
366 if isnan(option.fear) | |
367 option.fear = 0; | |
368 end | |
369 end | |
370 | |
371 | |
372 %% | |
373 function e = initialise(rm) | |
374 e = []; | |
375 | |
376 | |
377 function e = activity(e,rm,fpv,sc,ss,se) % without the box-cox transformation, revised coefficients | |
378 af = zeros(5,1); | |
379 af(1) = 0.6664* ((mean(rm) - 0.0559)/0.0337); % | |
380 af(2) = 0.6099 * ((mean(fpv{1}) - 13270.1836)/10790.655); | |
381 af(3) = 0.4486*((mean(cell2mat(sc)) - 1677.7)./570.34); | |
382 af(4) = -0.4639*((mean(cell2mat(ss)) - 250.5574)./205.3147); | |
383 af(5) = 0.7056*((mean(se) - 0.954)./0.0258); | |
384 af(isnan(af)) = []; | |
385 e(end+1,:) = sum(af)+5.4861; | |
386 e = {e af}; | |
387 | |
388 function e = valence(e,rm,fpv,kc,mo,ns) % without the box-cox transformation, revised coefficients | |
389 vf = zeros(5,1); | |
390 vf(1) = -0.3161 * ((std(rm) - 0.024254)./0.015667); | |
391 vf(2) = 0.6099 * ((mean(fpv{1}) - 13270.1836)/10790.655); | |
392 vf(3) = 0.8802 * ((mean(kc) - 0.5123)./0.091953); | |
393 vf(4) = 0.4565 * ((mean(mo) - -0.0019958)./0.048664); | |
394 ns(isnan(ns)) = []; | |
395 vf(5) = 0.4015 * ((mean(ns) - 131.9503)./47.6463); | |
396 vf(isnan(vf)) = []; | |
397 e(end+1,:) = sum(vf)+5.2749; | |
398 e = {e vf}; | |
399 | |
400 function e = tension(e,rm,fpv,kc,hc,nr) | |
401 tf = zeros(5,1); | |
402 tf(1) = 0.5382 * ((std(rm) - 0.024254)./0.015667); | |
403 tf(2) = -0.5406 * ((mean(fpv{1}) - 13270.1836)/10790.655); | |
404 tf(3) = -0.6808 * ((mean(kc) - 0.5124)./0.092); | |
405 tf(4) = 0.8629 * ((mean(hc) - 0.2962)./0.0459); | |
406 tf(5) = -0.5958 * ((mean(nr) - 71.8426)./46.9246); | |
407 tf(isnan(tf)) = []; | |
408 e(end+1,:) = sum(tf)+5.4679; | |
409 e = {e tf}; | |
410 | |
411 | |
412 % BASIC EMOTION PREDICTORS | |
413 | |
414 function e = happy(e,fpv,ss,cp,kc,mo) | |
415 ha_f = zeros(5,1); | |
416 ha_f(1) = 0.7438*((mean(cell2mat(fpv)) - 13270.1836)./10790.655); | |
417 ha_f(2) = -0.3965*((mean(cell2mat(ss)) - 250.5574)./205.3147); | |
418 ha_f(3) = 0.4047*((std(cell2mat(cp)) - 8.5321)./2.5899); | |
419 ha_f(4) = 0.7780*((mean(kc) - 0.5124)./0.092); | |
420 ha_f(5) = 0.6220*((mean(mo) - -0.002)./0.0487); | |
421 ha_f(isnan(ha_f)) = []; | |
422 e(end+1,:) = sum(ha_f)+2.6166; | |
423 e = {e ha_f}; | |
424 | |
425 function e = sad(e,ss,cp,mo,hc,nt) | |
426 sa_f = zeros(5,1); | |
427 sa_f(1) = 0.4324*((mean(cell2mat(ss)) - 250.5574)./205.3147); | |
428 sa_f(2) = -0.3137*((std(cell2mat(cp)) - 8.5321)./2.5899); | |
429 sa_f(3) = -0.5201*((mean(mo) - -0.0020)./0.0487); | |
430 sa_f(4) = -0.6017*((mean(hc) - 0.2962)./0.0459); | |
431 sa_f(5) = 0.4493*((mean(nt) - 42.2022)./36.7782); | |
432 sa_f(isnan(sa_f)) = []; | |
433 e(end+1,:) = sum(sa_f)+2.9756; | |
434 e = {e sa_f}; | |
435 | |
436 function e = tender(e,sc,rg,kc,hc,ns) | |
437 te_f = zeros(5,1); | |
438 te_f(1) = -0.2709*((mean(cell2mat(sc)) - 1677.7106)./570.3432); | |
439 te_f(2) = -0.4904*((std(rg) - 85.9387)./106.0767); | |
440 te_f(3) = 0.5192*((mean(kc) - 0.5124)./0.0920); | |
441 te_f(4) = -0.3995*((mean(hc) - 0.2962)./0.0459); | |
442 te_f(5) = 0.3391*((mean(ns) - 131.9503)./47.6463); | |
443 te_f(isnan(te_f)) = []; | |
444 e(end+1,:) = sum(te_f)+2.9756; | |
445 e = {e te_f}; | |
446 | |
447 function e = anger(e,rg,kc,se,nr) % | |
448 an_f = zeros(5,1); | |
449 %an_f(1) = -0.2353*((mean(pc) - 0.1462)./.1113); | |
450 an_f(2) = 0.5517*((mean(rg) - 85.9387)./106.0767); | |
451 an_f(3) = -.5802*((mean(kc) - 0.5124)./0.092); | |
452 an_f(4) = .2821*((mean(se) - 0.954)./0.0258); | |
453 an_f(5) = -.2971*((mean(nr) - 71.8426)./46.9246); | |
454 an_f(isnan(an_f)) = []; | |
455 e(end+1,:) = sum(an_f)+1.9767; | |
456 e = {e an_f}; | |
457 | |
458 function e = fear(e,rm,at,fpv,kc,mo) | |
459 fe_f = zeros(5,1); | |
460 fe_f(1) = 0.4069*((std(rm) - 0.0243)./0.0157); | |
461 fe_f(2) = -0.6388*((mean(at) - 0.0707)./0.015689218536423); | |
462 fe_f(3) = -0.2538*((mean(cell2mat(fpv)) - 13270.1836)./10790.655); | |
463 fe_f(4) = -0.9860*((mean(kc) - 0.5124)./0.0920); | |
464 fe_f(5) = -0.3144*((mean(mo) - -0.0019958)./0.048663550639094); | |
465 fe_f(isnan(fe_f)) = []; | |
466 e(end+1,:) = sum(fe_f)+2.7847; | |
467 e = {e fe_f}; | |
468 | |
469 function fp = noframe(fp) | |
470 fp = [fp(1);fp(end)]; |