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