tom@516
|
1 % Copyright 2012, Google, Inc.
|
tom@516
|
2 % Author: Richard F. Lyon
|
tom@516
|
3 %
|
tom@516
|
4 % This Matlab file is part of an implementation of Lyon's cochlear model:
|
tom@516
|
5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
|
tom@516
|
6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
|
tom@516
|
7 %
|
tom@516
|
8 % Licensed under the Apache License, Version 2.0 (the "License");
|
tom@516
|
9 % you may not use this file except in compliance with the License.
|
tom@516
|
10 % You may obtain a copy of the License at
|
tom@516
|
11 %
|
tom@516
|
12 % http://www.apache.org/licenses/LICENSE-2.0
|
tom@516
|
13 %
|
tom@516
|
14 % Unless required by applicable law or agreed to in writing, software
|
tom@516
|
15 % distributed under the License is distributed on an "AS IS" BASIS,
|
tom@516
|
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tom@516
|
17 % See the License for the specific language governing permissions and
|
tom@516
|
18 % limitations under the License.
|
tom@516
|
19
|
tom@516
|
20 %% Test/demo hacking for CARFAC Matlab stuff:
|
tom@516
|
21
|
tom@516
|
22 clear variables
|
tom@516
|
23
|
tom@516
|
24 %%
|
dicklyon@536
|
25 use_plan_file = 0;
|
dicklyon@536
|
26 if use_plan_file
|
dicklyon@536
|
27
|
dicklyon@536
|
28 file_signal = wavread('plan.wav');
|
dicklyon@536
|
29 file_signal = file_signal(8100+(1:20000)); % trim for a faster test
|
dicklyon@536
|
30
|
dicklyon@536
|
31 else
|
dicklyon@536
|
32 flist = [1000];
|
dicklyon@536
|
33 alist = [1];
|
dicklyon@536
|
34 flist = 1000;
|
dicklyon@536
|
35 alist = 1;
|
dicklyon@536
|
36 sine_signal = 0;
|
dicklyon@536
|
37 times = (0:19999)' / 22050;
|
dicklyon@536
|
38 for fno = 1:length(flist)
|
dicklyon@536
|
39 sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times);
|
dicklyon@536
|
40 end
|
dicklyon@536
|
41 growth_power = 0; % use 0 for flat, 4 or more for near exponential
|
dicklyon@536
|
42 file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power);
|
dicklyon@536
|
43 end
|
tom@516
|
44
|
tom@516
|
45 % repeat with negated signal to compare responses:
|
dicklyon@517
|
46 % file_signal = [file_signal; -file_signal];
|
tom@516
|
47
|
tom@516
|
48 % make a long test signal by repeating at different levels:
|
dicklyon@536
|
49 dB = -80;
|
dicklyon@536
|
50 test_signal = 10^(dB/20)* file_signal(1:4000) % lead-in [];
|
dicklyon@536
|
51 for dB = -80:20:80
|
tom@516
|
52 test_signal = [test_signal; file_signal * 10^(dB/20)];
|
tom@516
|
53 end
|
tom@516
|
54
|
tom@516
|
55 %%
|
tom@516
|
56 CF_struct = CARFAC_Design; % default design
|
tom@516
|
57
|
tom@516
|
58 %% Run mono, then stereo test:
|
tom@516
|
59
|
tom@516
|
60 agc_plot_fig_num = 6;
|
tom@516
|
61
|
dicklyon@536
|
62 for n_ears = 1 % 1:2
|
dicklyon@534
|
63 CF_struct = CARFAC_Init(CF_struct, n_ears);
|
tom@516
|
64
|
dicklyon@536
|
65 [CF_struct, nap_decim, nap, BM] = CARFAC_Run(CF_struct, test_signal, ...
|
dicklyon@534
|
66 agc_plot_fig_num);
|
tom@516
|
67
|
tom@516
|
68 % nap = deskew(nap); % deskew doesn't make much difference
|
tom@516
|
69
|
dicklyon@536
|
70 % dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 38:40, :).^2));
|
dicklyon@536
|
71 dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 20:50, :).^2));
|
dicklyon@536
|
72
|
dicklyon@534
|
73 if n_ears == 1 % because this hack doesn't work for binarual yet
|
dicklyon@536
|
74 MultiScaleSmooth(dB_BM(5000:200:end, :, :), 1);
|
dicklyon@536
|
75 % MultiScaleSmooth(nap_decim, 4);
|
dicklyon@517
|
76 end
|
tom@516
|
77
|
dicklyon@534
|
78 % Display results for 1 or 2 ears:
|
dicklyon@534
|
79 for ear = 1:n_ears
|
dicklyon@534
|
80 smooth_nap = nap_decim(:, :, ear);
|
dicklyon@534
|
81 if n_ears == 1
|
tom@516
|
82 mono_max = max(smooth_nap(:));
|
tom@516
|
83 end
|
dicklyon@534
|
84 figure(3 + ear + n_ears) % Makes figures 5, ...
|
tom@516
|
85 image(63 * ((max(0, smooth_nap)/mono_max)' .^ 0.5))
|
tom@516
|
86 title('smooth nap from nap decim')
|
tom@516
|
87 colormap(1 - gray);
|
tom@516
|
88 end
|
tom@516
|
89
|
tom@516
|
90 % Show resulting data, even though M-Lint complains:
|
tom@516
|
91 CF_struct
|
dicklyon@534
|
92 CF_struct.CAR_state
|
tom@516
|
93 CF_struct.AGC_state
|
tom@516
|
94 min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
|
tom@516
|
95
|
tom@516
|
96 % For the 2-channel pass, add a silent second channel:
|
tom@516
|
97 test_signal = [test_signal, zeros(size(test_signal))];
|
tom@516
|
98 end
|
tom@516
|
99
|
tom@516
|
100 % Expected result: Figure 3 looks like figure 2, a tiny bit darker.
|
tom@516
|
101 % and figure 4 is empty (all zero)
|