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

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