-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDemoAF_Basics.m
211 lines (189 loc) · 5.72 KB
/
DemoAF_Basics.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
%
% Demonstrations for introducting auditory filters
% DemoAF_Basics
% Irino, T.
% Created: 18 Mar 2010
% Modified: 18 Mar 2010
% Modified: 11 May 2010 (Figure number)
% Modified: 27 May 2010 (marker)
% Modified: 11 Jun 2010 (Figure number)
% Modified: 25 May 2015 (introduction of SwPrint)
% Modified: 12 Dec 2017 (introduction of DemoAF_ExcitationPattern)
% Modified: 21 Jan 2017 (exist('b1') == 0)
% Modified: 1 Jul 2020 GT> impulse response/ freq. responseをここで plot
%
%
% Note3 (2017/12/13)
% DemoAF_ExcitationPatternをDemoAF_Basics中に導入。
%
if exist('b1') == 0, % 単独で実行する場合用
%%% Param values from PUI 2003 %%%
n = 4;
b1 = 1.81;
c1 = -2.96;
b2 = 2.17;
c2 = 2.20;
frat0 = 0.466;
frat1 = 0.0109;
Nrsl = 2^12;
fs = 44100;
end; % exist('b1') == 0,
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1); clf;
%%% Frequnecy dependency %%%%
disp('Figure 1: Frequency response');
fpList = [250 500 1000 2000 4000 8000];
fpXTick = [100 250 500 1000 2000 4000 8000 16000];
ERBNXTick = Freq2ERB(fpXTick);
Ps = 50;
frat = frat0 + frat1*Ps;
for fp = fpList
fr1 = Fp2toFr1(n,b1,c1,b2,c2,frat,fp);
cGCresp = CmprsGCFrsp(fr1,fs,n,b1,c1,frat,b2,c2,Nrsl);
cGCFrsp = cGCresp.cGCFrsp;
cGCFrspdB = 20*log10(cGCFrsp/max(cGCFrsp));
freq = cGCresp.freq;
ERBNnum = Freq2ERB(freq);
plot(ERBNnum,cGCFrspdB)
ax = axis;
axis([ERBNXTick([1 end]) -70 5]);
set(gca,'XTick',ERBNXTick);
set(gca,'XTickLabel',fpXTick);
hx = xlabel('Frequency (Hz)');
hy = ylabel('Filter Gain (dB)');
title('Frequnecy response');
hold on
end;
drawnow
hold off
DemoAF_PrintFig([DirWork 'DemoAF_Basic_FilterBank'],SwPrint);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2); clf;
%%% Frequnecy dependency %%%%
disp('Figure 2: Center freq. vs. ERB width');
freq = 100:100:12000;
[ERBNnum ERBN] = Freq2ERB(freq);
loglog(freq,ERBN);
axis([50 15000 20 2500]);
xlabel('Center frequency (Hz)');
ylabel('Equivalent Rectangular Bandwidth (Hz)');
title('Center freq. vs. ERB width');
grid on
%set(gca,'Xtick',[50 100 200 500 1000 2000 5000 10000]);
%set(gca,'Xticklabel',[50 100 200 500 1000 2000 5000 10000]);
%set(gca,'Ytick',[20 50 100 200 500 1000 2000]);
%set(gca,'Yticklabel',[20 50 100 200 500 1000 2000]);
drawnow
hold off
DemoAF_PrintFig([DirWork 'DemoAF_Basic_BandWidth'],SwPrint);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(3); clf;
Marker = ['o','x','d','*','^','p','s'];
%%% Level dependency %%%%
disp('Figure 3: Filter level dependency');
fp = 2000;
PsList = 30:10:90;
cGCFrspdBMax = [];
cnt = 0;
for Ps = PsList
cnt = cnt +1;
frat = frat0 + frat1*Ps;
fr1 = Fp2toFr1(n,b1,c1,b2,c2,frat,fp);
cGCresp = CmprsGCFrsp(fr1,fs,n,b1,c1,frat,b2,c2,Nrsl);
cGCFrsp = cGCresp.cGCFrsp;
if cnt == 1, cGCFrspRef = max(cGCFrsp); end;
cGCFrspdB = 20*log10(cGCFrsp/cGCFrspRef);
freq = cGCresp.freq;
cGCFrspdBMax(cnt) = max(cGCFrspdB);
plot(freq,cGCFrspdB)
hold on;
plot(fp,cGCFrspdBMax(cnt),Marker(cnt))
axis([0 4000 -70 5]);
set(gca,'XTick',[0:1000:4000]);
text(fp*1.05, cGCFrspdBMax(cnt), int2str(Ps));
hx = xlabel('Frequency (Hz)');
hy = ylabel('Filter Gain (dB)');
end;
text(fp*1.15,2.5,'Input Level (dB)');
title('Level-dependent filter shape');
drawnow
hold off
DemoAF_PrintFig([DirWork 'DemoAF_Basic_FilterLevelDepend'],SwPrint);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Input Output function %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(4); clf;
disp('Figure 4: Input-output function');
OutputLevel = cGCFrspdBMax+PsList+33;
plot(PsList,OutputLevel,PsList,PsList,'--');
hold on
for cnt =1:length(OutputLevel);
plot(PsList(cnt),OutputLevel(cnt),Marker(cnt));
end;
axis([PsList([1 end]), PsList(1), PsList(end)+5]);
set(gca,'XTick',PsList);
hx = xlabel('Input Level (dB)');
set(gca,'YTick',PsList);
hy = ylabel('Output Level (dB)');
title('Input-Output function');
% legend('IO function','linear line',4);
drawnow
DemoAF_PrintFig([DirWork 'DemoAF_Basic_IOfunc'],SwPrint);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Exciation Pattern %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(5); clf;
disp('Figure 5: Excitation Pattern');
DemoAF_ExcitationPattern
drawnow
DemoAF_PrintFig([DirWork 'DemoAF_Basic_ExcitPattern'],2);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Impulse response of gammatone & gammachirp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(6);
disp('Figure 6: Impulse response of GT and GC')
fp = 2000;
fs = 44100;
n = 4;
b = 1.019; % default Gammatone
cGt = 0;
cGc = -3;
[gt, LenGt] = GammaChirp(fp,fs,n,b,cGt);
gmEnv = GammaChirp(fp,fs,n,b,cGt,0,'envelope');
[gc, LenGc] = GammaChirp(fp,fs,n,b,cGc);
tPl = 8;
nPl = 1:tPl*fs/1000;
tms = (nPl-1)/fs*1000;
bz = 2.5;
gme = [1; -1]*gmEnv(nPl);
plot(tms,gc(nPl)+bz,tms,gt(nPl),'--', ...
tms,gme,':k', tms,gme+bz,':k',[0 tPl],[ 0, bz; 0, bz],'k');
ax = axis;
axis([0 tPl, -1.2, 3.7]);
set(gca,'YTickLabel',' ');
%grid on
xlabel('Time (ms)');
ylabel('Amplitude (a.u.)');
legend('Gammachirp','Gammatone','Location','East');
title('Impulse Response');
DemoAF_PrintFig([DirWork 'DemoAF_Basic_GTGCimpRsp'],SwPrint);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Frequency response of gammatone & gammachirp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(7);
disp('Figure 7: Fourier spectrum of GT and GC')
Nfrsl = 1024;
[frspGT, freq] = freqz(gt,1,Nfrsl,fs);
[frspGC, freq] = freqz(gc,1,Nfrsl,fs);
GTdB = 20*log10(abs(frspGT));
GTdB = GTdB-max(GTdB);
GCdB = 20*log10(abs(frspGC));
GCdB = GCdB-max(GCdB);
plot(freq,GCdB,freq,GTdB,'--');
axis([0 fp*2, -50, 5]);
legend('Gammachirp','Gammatone');
title('Fourier Spectrum');
xlabel('Frequency (Hz)');
ylabel('Filter Gain (dB)');
DemoAF_PrintFig([DirWork 'DemoAF_Basic_GTGCfreqRsp'],SwPrint);
%%