annotate toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/test_auditory.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function test_auditory(test)
Daniel@0 2 % function test_auditory(test)
Daniel@0 3 % Test each of the functions in the Auditory Toolbox. The single argument
Daniel@0 4 % is a string, containing the word 'all' or the name of one routine from the
Daniel@0 5 % toolbox. This routine defaults to running all tests. There is a pause after
Daniel@0 6 % each plot, so be sure to hit the return key so the testing can proceed.
Daniel@0 7 %
Daniel@0 8
Daniel@0 9 % (c) 1998 Interval Research Corporation
Daniel@0 10
Daniel@0 11 if nargin < 1
Daniel@0 12 test = 'all';
Daniel@0 13 end
Daniel@0 14
Daniel@0 15 if strcmp(test,'agc') | strcmp(test,'all')
Daniel@0 16 disp('agc test');
Daniel@0 17 set_window_size(200, 150);
Daniel@0 18 agc(ones(1,20), [.5;.5])
Daniel@0 19 plot(agc(ones(1,30), [.8; .5])); pause;
Daniel@0 20 plot(agc(ones(1,30),[.4;.5])); pause;
Daniel@0 21 plot(agc(ones(1,30),[.4;.1])); pause;
Daniel@0 22 end
Daniel@0 23
Daniel@0 24 if strcmp(test,'CorrelogramArray') | strcmp(test,'all')
Daniel@0 25 disp('CorrelogramArray test');
Daniel@0 26 u=MakeVowel(4000,FMPoints(4000,120),16000,'u');
Daniel@0 27 soundsc(u,16000)
Daniel@0 28 coch=LyonPassiveEar(u,16000,1,4,.25);
Daniel@0 29 width = 256;
Daniel@0 30 cor=CorrelogramArray(coch,16000,16,width);
Daniel@0 31 [pixels frames] = size(cor);
Daniel@0 32 colormap(1-gray);
Daniel@0 33 for j=1:frames
Daniel@0 34 imagesc(reshape(cor(:,j),pixels/width,width));
Daniel@0 35 drawnow;
Daniel@0 36 end
Daniel@0 37 end
Daniel@0 38
Daniel@0 39 if strcmp(test,'CorrelogramFrame') | strcmp(test,'all')
Daniel@0 40 disp('CorrelogramFrame test');
Daniel@0 41 for j=20:-1:1
Daniel@0 42 c(j,:) = max(0,sin((1:256)/256*(21-j)*3*2*pi));
Daniel@0 43 end
Daniel@0 44 picture=CorrelogramFrame(c,128,1,256);
Daniel@0 45 imagesc(picture)
Daniel@0 46 colormap(1-gray)
Daniel@0 47 end
Daniel@0 48
Daniel@0 49 if strcmp(test,'CorrelogramMovie') | strcmp(test,'all')
Daniel@0 50 disp('CorrelogramMovie test');
Daniel@0 51 u=MakeVowel(4000,FMPoints(4000,120),16000,'u');
Daniel@0 52 soundsc(u,16000)
Daniel@0 53 coch=LyonPassiveEar(u,16000,1,4,.25);
Daniel@0 54 mov=CorrelogramMovie(coch,16000,16,256);
Daniel@0 55 movie(mov,-10,16)
Daniel@0 56 end
Daniel@0 57
Daniel@0 58 if strcmp(test,'CorrelogramPitch') | strcmp(test,'all')
Daniel@0 59 disp('CorrelogramPitch test');
Daniel@0 60 u=MakeVowel(20000,FMPoints(20000,120),22254,'u');
Daniel@0 61 cor=CorrelogramArray(u,22254,50,256);
Daniel@0 62 p=CorrelogramPitch(cor,256,22254);
Daniel@0 63 plot(p)
Daniel@0 64 axis([0 45 110 130]); pause;
Daniel@0 65
Daniel@0 66 coch=LyonPassiveEar(u,22254,1,4,.5);
Daniel@0 67 cor=CorrelogramArray(coch,22254,50,256);
Daniel@0 68 p=CorrelogramPitch(cor,256,22254);
Daniel@0 69 plot(p)
Daniel@0 70 axis([0 45 110 130]); pause;
Daniel@0 71
Daniel@0 72 u=MakeVowel(20000,FMPoints(20000,120),22254,'u');
Daniel@0 73 n=randn([1 20000]).*(1:20000)/20000;
Daniel@0 74 un=u+n/4;
Daniel@0 75 coch=LyonPassiveEar(un,22254,1,4,.5);
Daniel@0 76 cor=CorrelogramArray(coch,22254,50,256);
Daniel@0 77 [pitch sal]=CorrelogramPitch(cor,256,22254,100,200);
Daniel@0 78 plot(pitch); pause
Daniel@0 79 plot(sal); pause
Daniel@0 80 end
Daniel@0 81
Daniel@0 82 if strcmp(test,'DesignLyonFilters') | strcmp(test,'all')
Daniel@0 83 disp('DesignLyonFilters test');
Daniel@0 84 filts=DesignLyonFilters(16000);
Daniel@0 85 size(filts)
Daniel@0 86 filts(1:5,:)
Daniel@0 87
Daniel@0 88 resp=soscascade([1 zeros(1,255)],filts);
Daniel@0 89 freqResp=20*log10(abs(fft(resp(1:5:88,:)')));
Daniel@0 90 freqScale=(0:255)/256*16000;
Daniel@0 91 semilogx(freqScale(1:128),freqResp(1:128,:))
Daniel@0 92 axis([100 10000 -60 20]); pause;
Daniel@0 93 end
Daniel@0 94
Daniel@0 95 if strcmp(test,'EpsilonFromTauFS') | strcmp(test,'all')
Daniel@0 96 disp('EpsilonFromTauFS test');
Daniel@0 97 eps=EpsilonFromTauFS(5,1)
Daniel@0 98 filter(1, [1 eps-1],[1 zeros(1,9)])
Daniel@0 99 sosfilters([1 zeros(1,9)],[1 0 0 eps-1 0])
Daniel@0 100 end
Daniel@0 101
Daniel@0 102 if strcmp(test,'ERBSpace') | strcmp(test,'all')
Daniel@0 103 set_window_size(250, 150);
Daniel@0 104 disp('ERBSpace test')
Daniel@0 105 plot(ERBSpace)
Daniel@0 106 end
Daniel@0 107
Daniel@0 108 if strcmp(test,'FMPoints') | strcmp(test,'all')
Daniel@0 109 disp('FMPoints test');
Daniel@0 110 u=MakeVowel(20000,FMPoints(20000,120), 22050,'u');
Daniel@0 111 soundsc(u/max(u), 22050)
Daniel@0 112 end
Daniel@0 113
Daniel@0 114 if strcmp(test,'FreqResp') | strcmp(test,'all')
Daniel@0 115 disp('FreqResp test');
Daniel@0 116 filts=DesignLyonFilters(16000);
Daniel@0 117 f=10:10:7990;
Daniel@0 118 resp=FreqResp(filts(2, :), f, 16000);
Daniel@0 119 semilogx(f,resp);
Daniel@0 120 axis([100 10000 -50 20]);
Daniel@0 121 end
Daniel@0 122
Daniel@0 123 if strcmp(test,'LyonPassiveEar') | strcmp(test,'all')
Daniel@0 124 disp('LyonPassiveEar test');
Daniel@0 125 is=LyonPassiveEar([1 zeros(1,255)],16000,1);
Daniel@0 126 imagesc(min(is, 0.0004)); pause
Daniel@0 127
Daniel@0 128 s=sin((0:2041)/20000*2*pi*1000);
Daniel@0 129 ys=LyonPassiveEar(s,20000,20);
Daniel@0 130 imagesc(ys/max(max(ys))); pause;
Daniel@0 131
Daniel@0 132 tap = wavread('tapestry.wav');
Daniel@0 133 coch=LyonPassiveEar(tap,16000,100);
Daniel@0 134 imagesc(coch/max(max(coch))); pause;
Daniel@0 135 end
Daniel@0 136
Daniel@0 137 if strcmp(test,'MakeERBFilters') | strcmp(test,'all')
Daniel@0 138 disp('MakeERBFilters test');
Daniel@0 139 fcoefs = MakeERBFilters(16000,10,100);
Daniel@0 140 y = ERBFilterBank([1 zeros(1,511)], fcoefs);
Daniel@0 141 resp = 20*log10(abs(fft(y')));
Daniel@0 142 freqScale = (0:511)/512*16000;
Daniel@0 143 semilogx(freqScale(1:255),resp(1:255,:));
Daniel@0 144 axis([100 16000 -60 0])
Daniel@0 145 xlabel('Frequency (Hz)');
Daniel@0 146 ylabel('Filter Response (dB)'); pause;
Daniel@0 147
Daniel@0 148 tap = wavread('tapestry.wav');
Daniel@0 149 fcoefs=MakeERBFilters(16000,40,100);
Daniel@0 150 coch=ERBFilterBank(tap, fcoefs);
Daniel@0 151 for j=1:size(coch,1)
Daniel@0 152 c=max(coch(j,:),0);
Daniel@0 153 c=filter([1],[1 -.99],c);
Daniel@0 154 coch(j,:)=c;
Daniel@0 155 end
Daniel@0 156 imagesc(coch);
Daniel@0 157 end
Daniel@0 158
Daniel@0 159 if strcmp(test,'MakeVowel') | strcmp(test,'all')
Daniel@0 160 disp('MakeVowel test');
Daniel@0 161 vowels=[MakeVowel(10000,100,16000,'a') ...
Daniel@0 162 MakeVowel(10000,100,16000,'i') ...
Daniel@0 163 MakeVowel(10000,100,16000,'u')];
Daniel@0 164 soundsc(vowels,16000);
Daniel@0 165
Daniel@0 166 vowels=[MakeVowel(1000,100,16000,'a')...
Daniel@0 167 MakeVowel(1000,100,16000,'i') ...
Daniel@0 168 MakeVowel(1000,100,16000,'u')];
Daniel@0 169 s=spectrogram(vowels,256,2,2);
Daniel@0 170 imagesc(s); pause
Daniel@0 171 end
Daniel@0 172
Daniel@0 173 if strcmp(test,'MeddisHairCell') | strcmp(test,'all')
Daniel@0 174 disp('MeddisHairCell test');
Daniel@0 175 tone=sin((0:4999)/20000*2*pi*1000);
Daniel@0 176 s=[zeros(1,5000) ...
Daniel@0 177 tone*10^(40/20-1.35) zeros(1,5000) ...
Daniel@0 178 tone*10^(45/20-1.35) zeros(1,5000) ...
Daniel@0 179 tone*10^(50/20-1.35) zeros(1,5000) ...
Daniel@0 180 tone*10^(55/20-1.35) zeros(1,5000) ...
Daniel@0 181 tone*10^(60/20-1.35) zeros(1,5000) ...
Daniel@0 182 tone*10^(65/20-1.35) zeros(1,5000) ...
Daniel@0 183 tone*10^(70/20-1.35) zeros(1,5000) ...
Daniel@0 184 tone*10^(75/20-1.35) zeros(1,5000) ...
Daniel@0 185 tone*10^(80/20-1.35)];
Daniel@0 186 y=MeddisHairCell(s,20000);
Daniel@0 187 plot((1:90000)/20000,y(1:90000)); pause
Daniel@0 188 end
Daniel@0 189
Daniel@0 190 if strcmp(test,'mfcc') | strcmp(test,'all')
Daniel@0 191 disp('mfcc test');
Daniel@0 192 set_window_size(348, 188);
Daniel@0 193 tap = wavread('tapestry.wav');
Daniel@0 194 [ceps,freqresp,fb,fbrecon,freqrecon] = mfcc(tap,16000,100);
Daniel@0 195 imagesc(ceps);
Daniel@0 196 colormap(1-gray); pause
Daniel@0 197 imagesc(flipud(freqresp)); pause
Daniel@0 198 imagesc(flipud(fb)); pause
Daniel@0 199 imagesc(flipud(fbrecon)); pause
Daniel@0 200 imagesc(flipud(freqrecon)); pause
Daniel@0 201 end
Daniel@0 202
Daniel@0 203 if strcmp(test,'proclpc') | strcmp(test,'all')
Daniel@0 204 disp('proclpc test');
Daniel@0 205 set_window_size(348, 188);
Daniel@0 206 [tap sr]= wavread('tapestry.wav');
Daniel@0 207 lpc_spec(tap,sr,13); pause
Daniel@0 208 lpc_spec(tap,sr,26); pause
Daniel@0 209 end
Daniel@0 210
Daniel@0 211 if strcmp(test,'rasta') | strcmp(test,'all')
Daniel@0 212 disp('rasta test');
Daniel@0 213 tap = wavread('tapestry.wav');
Daniel@0 214 [ceps,freqresp,fb,fbrecon,freqrecon] = mfcc(tap,16000,100);
Daniel@0 215 rastaout = rasta(ceps,100);
Daniel@0 216
Daniel@0 217 mfccDCTMatrix = 1/sqrt(40/2)*cos((0:(13-1))' * ...
Daniel@0 218 (2*(0:(40-1))+1) * pi/2/40);
Daniel@0 219 mfccDCTMatrix(1,:) = mfccDCTMatrix(1,:)*sqrt(2)/2;
Daniel@0 220
Daniel@0 221 rastarecon = 0*fbrecon;
Daniel@0 222 for i=1:size(rastaout,2)
Daniel@0 223 rastarecon(:,i) = mfccDCTMatrix' * rastaout(:,i);
Daniel@0 224 end
Daniel@0 225 imagesc(flipud(rastarecon));
Daniel@0 226 end
Daniel@0 227
Daniel@0 228 if strcmp(test,'SecondOrderFilter') | strcmp(test,'all')
Daniel@0 229 disp('SecondOrderFilter test');
Daniel@0 230 f=10:10:7990;
Daniel@0 231 sos=SecondOrderFilter(3000,5,16000)
Daniel@0 232 filt=[1 0 0 sos(2:3)]
Daniel@0 233 semilogx(f,FreqResp(filt,f,16000)); pause
Daniel@0 234
Daniel@0 235 filt=[sos 0 0]
Daniel@0 236 semilogx(f,FreqResp(filt,f,16000)); pause
Daniel@0 237
Daniel@0 238 sos=SecondOrderFilter(3000,2,16000)
Daniel@0 239 filt=[sos 0 0]
Daniel@0 240 semilogx(f,FreqResp(filt,f,16000)); pause
Daniel@0 241 end
Daniel@0 242
Daniel@0 243 if strcmp(test,'SeneffEar') | strcmp(test,'all')
Daniel@0 244 disp('SeneffEar test');
Daniel@0 245 s=[zeros(1,160) sin(2000*2*pi/16000*(1:1120))];
Daniel@0 246 y=SeneffEar(s,16000,15); pause;
Daniel@0 247
Daniel@0 248 tap = wavread('tapestry.wav');
Daniel@0 249 hc=SeneffEar(tap,16000);
Daniel@0 250 for j=1:40
Daniel@0 251 c=hc(j,:);
Daniel@0 252 c=filter([1],[1, -.99],c);
Daniel@0 253 h(j,:)=c(1:100:50381);
Daniel@0 254 end
Daniel@0 255 clf; imagesc(h); pause;
Daniel@0 256 end
Daniel@0 257
Daniel@0 258 if strcmp(test,'SetGain') | strcmp(test,'all')
Daniel@0 259 disp('SetGain test');
Daniel@0 260 filts=DesignLyonFilters(16000);
Daniel@0 261 filt=filts(42,:)
Daniel@0 262 f=10:10:7990;
Daniel@0 263 semilogx(f,FreqResp(filt,f,16000)); pause;
Daniel@0 264
Daniel@0 265 newFilt = SetGain(filt, 10, 1960, 16000);
Daniel@0 266 semilogx(f, FreqResp(newFilt, f, 16000)); pause
Daniel@0 267 end
Daniel@0 268
Daniel@0 269 if strcmp(test,'soscascade') | strcmp(test,'all')
Daniel@0 270 disp('soscascade test');
Daniel@0 271 soscascade([1 0 0 0 0],[1 0 0 -.9 0;1 1 0 0 0])
Daniel@0 272 end
Daniel@0 273
Daniel@0 274 if strcmp(test,'sosfilters') | strcmp(test,'all')
Daniel@0 275 disp('sosfilters test');
Daniel@0 276 sosfilters([1 0 0 0 0 0],[1 0 0 -.9 0;1 0 0 -.8 0])
Daniel@0 277 sosfilters([1 0 0 0 0 0;2 0 0 0 0 0], ...
Daniel@0 278 [1 0 0 -.9 0;1 0 0 -.8 0])
Daniel@0 279 sosfilters([1 0 0 0 0 0;2 0 0 0 0 0],[1 0 0 -.9 0])
Daniel@0 280 end
Daniel@0 281
Daniel@0 282 if strcmp(test,'spectrogram') | strcmp(test,'all')
Daniel@0 283 disp('spectrogram test');
Daniel@0 284 tap = wavread('tapestry.wav');
Daniel@0 285 spec=spectrogram(tap,64,2,1);
Daniel@0 286 imagesc(spec); pause;
Daniel@0 287 end
Daniel@0 288
Daniel@0 289 if strcmp(test,'synlpc') | strcmp(test,'all')
Daniel@0 290 disp('synlpc test');
Daniel@0 291 [tap sr] = wavread('tapestry.wav');
Daniel@0 292 [aCoeff,resid,pitch,G,parcor,stream] = proclpc(tap,sr,13);
Daniel@0 293 syntap = synlpc(aCoeff, stream, sr, G);;
Daniel@0 294 soundsc(syntap,16000);
Daniel@0 295
Daniel@0 296 [aCoeff,resid,pitch,G,parcor,stream] = proclpc(tap,sr,13);
Daniel@0 297 stream=randn(size(stream));
Daniel@0 298 syntap = synlpc(aCoeff, stream, sr, G);;
Daniel@0 299 soundsc(syntap,16000);
Daniel@0 300 end
Daniel@0 301
Daniel@0 302 if strcmp(test,'WhiteVowel') | strcmp(test,'all')
Daniel@0 303 disp('WhiteVowel test');
Daniel@0 304 [tap sr] = wavread('tapestry.wav');
Daniel@0 305 whitetap = WhiteVowel(tap,16000,13,1000);
Daniel@0 306 soundsc(whitetap, 16000);
Daniel@0 307 end
Daniel@0 308
Daniel@0 309 function lpc_spec(tap,sr,L)
Daniel@0 310 [aCoeff,resid,pitch,G,parcor,stream] = proclpc(tap,sr,L);
Daniel@0 311 cft=0:(1/255):1;
Daniel@0 312 spec = zeros(128, size(aCoeff,2));
Daniel@0 313 for nframe=1:size(aCoeff,2)
Daniel@0 314 gain=20*log10(G(nframe)) * 0;
Daniel@0 315 for index=1:size(aCoeff,1)
Daniel@0 316 gain = gain + aCoeff(index,nframe)*exp(-i*2*pi*cft).^index;
Daniel@0 317 end
Daniel@0 318 gain = abs(1./gain);
Daniel@0 319 spec(:,nframe) = 20*log10(gain(1:128))';
Daniel@0 320 end
Daniel@0 321 imagesc(flipud(spec));
Daniel@0 322
Daniel@0 323
Daniel@0 324
Daniel@0 325 function set_window_size(width, height)
Daniel@0 326 cursize = get(gcf, 'position');
Daniel@0 327 cursize(3) = width+1;
Daniel@0 328 cursize(4) = height+1;
Daniel@0 329 set(gcf, 'position', cursize);
Daniel@0 330
Daniel@0 331
Daniel@0 332