dan@0: function eventBased(script, fileName, directory, conf) dan@0: %% dan@0: %MOBILAB 2012 - 2013 dan@0: % dan@0: % Input parameters dan@0: % -script: Each row is a representation of a certain class dan@0: % Each column contains the value (ones) of wich class is active at dan@0: % that certain moment. dan@0: % [N x M] matrix: dan@0: % -N: nr classes dan@0: % -M: nr of frames in the script dan@0: % -fileName: Is the name of the output text file. dan@0: % -directory: Is the location where the output text file must be written dan@0: % -conf: Is a struct and contains information about the time of the dan@0: % differrent frames dan@0: %% dan@0: fileID = fopen([directory filesep fileName],'a'); dan@0: dan@0: %Determine the number of classes and the number of framees dan@0: [nr_classes nr_frames] = size(script(1:16,:)); dan@0: %classnames dan@0: eventID = {'alert','clearthroat','cough','doorslam','drawer','keyboard','keys',... dan@0: 'doorknock','laughter','mouse','pageturn','pendrop','phone','printer','speech','switch'}; dan@0: k=1; dan@0: dan@0: for class=1:nr_classes dan@0: b = [1 -1]; dan@0: changes = conv(script(class,:),b); %Find transitions dan@0: changes = changes(1:length(script)); %Apply same lenght as script dan@0: dan@0: onset = find(changes==1); %Find the 0-1 transitions // onset dan@0: offset = find(changes==-1); %Find the 1-0 transitions // offset dan@0: dan@0: for(nr_transtion=1 : length(onset)) dan@0: onsetOffset(k,1) = onset(nr_transtion)*(conf.framestep_ms/1000); dan@0: onsetOffset(k,2) = offset(nr_transtion)*(conf.framestep_ms/1000); dan@0: classifiedEvent{k,1} = eventID{1,class}; dan@0: k=k+1; dan@0: end, dan@0: end, dan@0: dan@0: % Sort the data with respect to the onset times dan@0: [data_sorted(:,1) I] = sort(onsetOffset(:,1)); dan@0: data_sorted(:,2) = onsetOffset(I,2); dan@0: dan@0: for (nr=1:length(data_sorted(:,1))) dan@0: fprintf(fileID,'%f',data_sorted(nr,1)); %Print onset time dan@0: fprintf(fileID, '\t'); %Print space dan@0: fprintf(fileID,'%f',data_sorted(nr,2)); %Print offset time dan@0: fprintf(fileID, '\t'); %Print space dan@0: fprintf(fileID,'%s',classifiedEvent{I(nr),1}); dan@0: fprintf(fileID,'\n'); %Print newline dan@0: end, dan@0: dan@0: fclose(fileID); dan@0: dan@0: end dan@0: