annotate listeningTest/pairComp/readPairComp.m @ 15:24be5e9ce25b tip

Update README
author Brecht De Man <brecht.deman@bcu.ac.uk>
date Thu, 20 Sep 2018 12:23:20 +0200
parents 5e72201496c8
children
rev   line source
b@0 1 function tstDat=readPairComp(testFile)
b@0 2
b@0 3 % pair comparison specifications
b@0 4 %
b@0 5 % NAME
b@0 6 % pair comparison test #1
b@0 7 %
b@0 8 % NBSOUNDS: 3
b@0 9 % RANDOM?: 0
b@0 10 % REPETITIONS?: 0
b@0 11 %
b@0 12 % NBCOMBINATIONS: 3
b@0 13 % COMBINATIONS
b@0 14 % 2 3
b@0 15 % 2 1
b@0 16 % 3 1
b@0 17 %
b@0 18 % NBSCALES: 1
b@0 19 % SCALES
b@0 20 % SCALE:
b@0 21 % Global difference
b@0 22 % LEVEL
b@0 23 % min 1 A & B are the same
b@0 24 % max 7 A & B are very different
b@0 25 % step 1
b@0 26 %
b@0 27 % NBQUESTIONS: 2
b@0 28 % QUESTIONS
b@0 29 % 2 I prefer A
b@0 30 % 1 I prefer B
b@0 31 % 0 I think they are both very annoying % the index in front show if the questions are linked to others (mutually exclusive)
b@0 32 %
b@0 33 % COMMENTS?: 1 % ask if a comment field should be displayed (1=yes 0=no)
b@0 34 %
b@0 35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 36 %
b@0 37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 38
b@0 39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 40 %Initialization
b@0 41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 42
b@0 43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 44 % file parsing
b@0 45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b@0 46
b@0 47 tstDat.name=[];
b@0 48 tstDat.COM=1;
b@0 49 tstDat.RAN=0;
b@0 50 tstDat.REP=0;
b@0 51 tstDat.scale=[];
b@0 52
b@0 53 fid=fopen(testFile,'r');
b@0 54 while ~feof(fid)
b@0 55 lin=fgetl(fid);
b@0 56 [word1,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 57
b@2 58 if (~COUNT || ~strcmp(word1,'%'))
b@0 59 switch upper(word1)
b@0 60 case 'NAME'
b@0 61 tstDat.name=fgetl(fid);
b@0 62
b@0 63 case 'NBSOUNDS:'
b@0 64 [nbSnd,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 65 tstDat.nbSnd=nbSnd;
b@0 66
b@0 67 % only if specific combinations need to be tested (as opposed to
b@0 68 % all possible combinations)
b@0 69 % case 'NBCOMBINATIONS:'
b@0 70 % [nbComb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 71 % tstDat.nbComb=nbComb;
b@0 72 %
b@0 73 % case 'COMBINATIONS'
b@0 74 % for noComb=1:nbComb
b@0 75 % lin=fgetl(fid);
b@0 76 % if ~isempty(lin)
b@0 77 % if lin(1)~='%'
b@0 78 % [comb,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',2);
b@0 79 % tstDat.comb(noComb,:)=comb;
b@0 80 % end
b@0 81 % end
b@0 82 % end
b@0 83
b@0 84 case 'NBSCALES:'
b@0 85 [nbScale,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 86 tstDat.nbScale=nbScale;
b@0 87 case 'SCALES'
b@0 88 for noScale=1:nbScale
b@0 89 while ~feof(fid)
b@0 90 lin=fgetl(fid);
b@0 91 [header,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%s',1);
b@0 92 switch firstWord(header)
b@0 93 case 'SCALE:'
b@0 94 name=fgetl(fid);
b@0 95 case 'min'
b@0 96 lin=lin(NEXTINDEX:end);
b@0 97 [minn,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
b@0 98 level{1}=lin(NEXTINDEX:end); %%
b@0 99 case 'max'
b@0 100 lin=lin(NEXTINDEX:end);
b@0 101 [maxx,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
b@0 102 level{3}=lin(NEXTINDEX:end); %%
b@0 103
b@0 104 case 'step'
b@0 105 lin=lin(NEXTINDEX:end);
b@0 106 [stepp,COUNT,ERRMSG,NEXTINDEX]=sscanf(lin,'%d',1); %%
b@0 107 level{2}=lin(NEXTINDEX:end); %%
b@0 108 break
b@0 109 end
b@0 110
b@0 111 end
b@0 112 tstDat.scale(noScale).name=name;
b@0 113 tstDat.scale(noScale).maxx=maxx;
b@0 114 tstDat.scale(noScale).minn=minn;
b@0 115 tstDat.scale(noScale).stepp=stepp;
b@0 116 tstDat.scale(noScale).level=level;
b@0 117 end
b@0 118
b@0 119 case 'NBQUESTIONS:'
b@0 120 [nbQuest,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 121 tstDat.nbQuest=nbQuest;
b@0 122 case 'QUESTIONS'
b@0 123 for noQuest=1:nbQuest
b@0 124 lin=fgetl(fid);
b@0 125 [tstDat.link(noQuest),COUNT,ERRMSG,NEXTINDEX] = sscanf(lin,'%d',1);
b@0 126 tstDat.quest{noQuest}=lin(NEXTINDEX:end);
b@0 127 end
b@0 128 case 'COMMENTS?:'
b@0 129 [COM,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 130 tstDat.COM=COM;
b@0 131
b@0 132 % assume random order is desired for now
b@0 133 % case 'RANDOM?:'
b@0 134 % [RAN,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 135 % tstDat.RAN=RAN;
b@0 136
b@0 137 case 'REPETITIONS?:' % number of times samples should be repeated
b@0 138 [REP,COUNT,ERRMSG,NEXTINDEX] = sscanf(lin(NEXTINDEX:end),'%d',1);
b@0 139 tstDat.REP=REP;
b@0 140
b@0 141 end
b@0 142 end
b@0 143 end
b@0 144
b@0 145
b@0 146 comb = combnk(1:nbSnd,2);
b@0 147 nbComb = length(comb(:,1));
b@0 148
b@0 149 % repeat comparisons a number of times throughout test
b@0 150 if REP
b@0 151 comb = repmat(comb,tstDat.REP+1,1);
b@0 152 end
b@0 153
b@0 154 % randomise order
b@0 155 comb = comb(randperm(nbComb),:);
b@0 156
b@0 157 % randomly flip left and right column numbers
b@0 158 flipsides = ceil(2*rand(nbComb,1))-1; % random string of nbComb 0's and 1's
b@0 159 comb = [comb((1:nbComb)'+ flipsides*nbComb) comb((1:nbComb)' + nbComb - flipsides*nbComb)];
b@0 160
b@0 161 %save('lastComb','comb');
b@0 162 % TO DO: Add recall in case of crash/interruption.
b@0 163
b@0 164 tstDat.comb = comb;
b@0 165 tstDat.nbComb = nbComb;
b@0 166
b@0 167 fclose(fid);
b@0 168
b@0 169 function word=firstWord(word)
b@0 170
b@0 171 if ~isempty(word)
b@0 172 if word(1)=='%'
b@0 173 word='';
b@0 174 end
b@0 175 else
b@0 176 word='';
b@0 177 end