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