Mercurial > hg > dcase2013_ed_vuegenetal
comparison functions/challange/eventBased.m @ 0:2fadb31a9d55 tip
Import code by Vuegen et al
author | Dan Stowell <dan.stowell@elec.qmul.ac.uk> |
---|---|
date | Fri, 11 Oct 2013 12:02:43 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2fadb31a9d55 |
---|---|
1 function eventBased(script, fileName, directory, conf) | |
2 %% | |
3 %MOBILAB 2012 - 2013 | |
4 % | |
5 % Input parameters | |
6 % -script: Each row is a representation of a certain class | |
7 % Each column contains the value (ones) of wich class is active at | |
8 % that certain moment. | |
9 % [N x M] matrix: | |
10 % -N: nr classes | |
11 % -M: nr of frames in the script | |
12 % -fileName: Is the name of the output text file. | |
13 % -directory: Is the location where the output text file must be written | |
14 % -conf: Is a struct and contains information about the time of the | |
15 % differrent frames | |
16 %% | |
17 fileID = fopen([directory filesep fileName],'a'); | |
18 | |
19 %Determine the number of classes and the number of framees | |
20 [nr_classes nr_frames] = size(script(1:16,:)); | |
21 %classnames | |
22 eventID = {'alert','clearthroat','cough','doorslam','drawer','keyboard','keys',... | |
23 'doorknock','laughter','mouse','pageturn','pendrop','phone','printer','speech','switch'}; | |
24 k=1; | |
25 | |
26 for class=1:nr_classes | |
27 b = [1 -1]; | |
28 changes = conv(script(class,:),b); %Find transitions | |
29 changes = changes(1:length(script)); %Apply same lenght as script | |
30 | |
31 onset = find(changes==1); %Find the 0-1 transitions // onset | |
32 offset = find(changes==-1); %Find the 1-0 transitions // offset | |
33 | |
34 for(nr_transtion=1 : length(onset)) | |
35 onsetOffset(k,1) = onset(nr_transtion)*(conf.framestep_ms/1000); | |
36 onsetOffset(k,2) = offset(nr_transtion)*(conf.framestep_ms/1000); | |
37 classifiedEvent{k,1} = eventID{1,class}; | |
38 k=k+1; | |
39 end, | |
40 end, | |
41 | |
42 % Sort the data with respect to the onset times | |
43 [data_sorted(:,1) I] = sort(onsetOffset(:,1)); | |
44 data_sorted(:,2) = onsetOffset(I,2); | |
45 | |
46 for (nr=1:length(data_sorted(:,1))) | |
47 fprintf(fileID,'%f',data_sorted(nr,1)); %Print onset time | |
48 fprintf(fileID, '\t'); %Print space | |
49 fprintf(fileID,'%f',data_sorted(nr,2)); %Print offset time | |
50 fprintf(fileID, '\t'); %Print space | |
51 fprintf(fileID,'%s',classifiedEvent{I(nr),1}); | |
52 fprintf(fileID,'\n'); %Print newline | |
53 end, | |
54 | |
55 fclose(fileID); | |
56 | |
57 end | |
58 |