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