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