annotate Code/Descriptors/Matlab/MPEG7/FromWeb/VoiceSauce/func_readEGGfile.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
rev   line source
Dawn@4 1 function [EGGData, FrameT] = func_readEGGfile(EGGfile, EGGheaders, EGGtimelabel)
Dawn@4 2 % [EGGData, FrameT] = func_readEGGfile(EGGfile, EGGheaders, EGGtimelabel)
Dawn@4 3 % Input: EGGfile - .egg file name
Dawn@4 4 % EGGheaders - headers to look for in the .egg file
Dawn@4 5 % EGGtimelabel - label representing time
Dawn@4 6 % Output: EGGData
Dawn@4 7 % FrameT - time vector
Dawn@4 8 % Notes:
Dawn@4 9 %
Dawn@4 10 % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA
Dawn@4 11 % Copyright UCLA SPAPL 2009
Dawn@4 12
Dawn@4 13 fid = fopen(EGGfile, 'r');
Dawn@4 14 tmp = textscan(fid, '%s', 1, 'delimiter', '\n');
Dawn@4 15 data = textscan(fid, '%s', 'delimiter', '\n');
Dawn@4 16 fclose(fid);
Dawn@4 17
Dawn@4 18 EGGheaders = textscan(EGGheaders, '%s', 'delimiter', ',');
Dawn@4 19 EGGheaders = EGGheaders{1};
Dawn@4 20
Dawn@4 21 % find the index of the "Entry definition and order" header
Dawn@4 22 headers = textscan(tmp{1}{1}, '%s', 'delimiter', '\t');
Dawn@4 23 inx = 0;
Dawn@4 24 for k=1:length(headers{1})
Dawn@4 25 if (strcmp(removeExtraSpace(headers{1}{k}), 'Entry definition and order'))
Dawn@4 26 inx = k;
Dawn@4 27 break;
Dawn@4 28 end
Dawn@4 29 end
Dawn@4 30
Dawn@4 31 % now extract the entry definition from the next data
Dawn@4 32 defn = textscan(data{1}{1}, '%s', 'delimiter', '\t');
Dawn@4 33 defn = defn{1}{inx};
Dawn@4 34
Dawn@4 35 defn_headers = textscan(defn, '%s', 'delimiter', ':,');
Dawn@4 36 EGGInx = [];
Dawn@4 37
Dawn@4 38 for k=1:length(EGGheaders)
Dawn@4 39 for n=1:length(defn_headers{1})
Dawn@4 40 str = removeExtraSpace(defn_headers{1}{n});
Dawn@4 41 if (strcmp(EGGheaders{k}, str) == 1)
Dawn@4 42 EGGInx = [EGGInx n];
Dawn@4 43 break;
Dawn@4 44 end
Dawn@4 45
Dawn@4 46 if (n==length(defn_headers{1}))
Dawn@4 47 EGGInx = [EGGInx -1]; % header was not found, set err code
Dawn@4 48 end
Dawn@4 49 end
Dawn@4 50 end
Dawn@4 51
Dawn@4 52 % now extract the time data
Dawn@4 53 for k=1:length(defn_headers{1})
Dawn@4 54 if (strcmp(EGGtimelabel, defn_headers{1}{k}) == 1)
Dawn@4 55 FrameInx = k;
Dawn@4 56 break;
Dawn@4 57 end
Dawn@4 58 end
Dawn@4 59
Dawn@4 60 EGGInx = EGGInx + 1;
Dawn@4 61 FrameInx = FrameInx + 1;
Dawn@4 62
Dawn@4 63 FrameT = zeros(1, length(data{1}));
Dawn@4 64 EGGData = cell(1, length(EGGInx));
Dawn@4 65 for k=1:length(EGGInx)
Dawn@4 66 EGGData{k} = zeros(1, length(data{1}));
Dawn@4 67 end
Dawn@4 68
Dawn@4 69 for k=1:length(data{1})
Dawn@4 70 dat = textscan(data{1}{k}, '%s', 'delimiter', '\t');
Dawn@4 71 FrameT(k) = str2num(dat{1}{FrameInx});
Dawn@4 72
Dawn@4 73 for n=1:length(EGGInx)
Dawn@4 74 if (EGGInx(n) ~= 0)
Dawn@4 75 val = str2double(dat{1}{EGGInx(n)});
Dawn@4 76 if (isnan(val))
Dawn@4 77 val = 0;
Dawn@4 78 end
Dawn@4 79 EGGData{n}(k) = val;
Dawn@4 80 end
Dawn@4 81 end
Dawn@4 82 end
Dawn@4 83
Dawn@4 84
Dawn@4 85 % removes extra spaces at the start and end of words
Dawn@4 86 function str = removeExtraSpace(s)
Dawn@4 87 str = s;
Dawn@4 88 while (1)
Dawn@4 89 if (str(1) == ' ')
Dawn@4 90 str = str(2:end);
Dawn@4 91 else
Dawn@4 92 break;
Dawn@4 93 end
Dawn@4 94 end
Dawn@4 95
Dawn@4 96 while(1)
Dawn@4 97 if (str(end) == ' ')
Dawn@4 98 str = str(1:end-1);
Dawn@4 99 else
Dawn@4 100 break;
Dawn@4 101 end
Dawn@4 102 end