annotate matlab/bmm/carfac/CARFAC_hacking.m @ 511:a39da72c7980

Example config for OSC
author tomwalters@google.com
date Fri, 22 Jun 2012 12:27:44 +0000
parents a0869cb1c99b
children 1d720e7fffdf
rev   line source
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 %%
dicklyon@504 25
dicklyon@498 26 use_plan_file = 1;
dicklyon@504 27 dB_list = -60:20:40
dicklyon@504 28
dicklyon@475 29 if use_plan_file
dicklyon@475 30
dicklyon@475 31 file_signal = wavread('plan.wav');
dicklyon@502 32 % file_signal = file_signal(8100+(1:20000)); % trim for a faster test
dicklyon@502 33 file_signal = file_signal(10000+(1:10000)); % trim for a faster test
dicklyon@475 34
dicklyon@475 35 else
dicklyon@504 36 flist = 1400 + (1:4)*200;
dicklyon@504 37 alist = [1, 1, 1, 1];
dicklyon@502 38 sine_signal = 0;
dicklyon@504 39 times = (0:9999)' / 22050;
dicklyon@502 40 for fno = 1:length(flist)
dicklyon@502 41 sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times);
dicklyon@502 42 end
dicklyon@502 43 growth_power = 0; % use 0 for flat, 4 or more for near exponential
dicklyon@502 44 file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power);
dicklyon@475 45 end
tom@455 46
tom@455 47 % make a long test signal by repeating at different levels:
dicklyon@502 48 % dB = dB_list(1);
dicklyon@502 49 % test_signal = 10^(dB/20)* file_signal(1:4000) % lead-in [];
dicklyon@502 50 test_signal = [];
dicklyon@502 51 for dB = dB_list
tom@455 52 test_signal = [test_signal; file_signal * 10^(dB/20)];
tom@455 53 end
tom@455 54
tom@455 55
tom@455 56 %% Run mono, then stereo test:
tom@455 57
tom@455 58 agc_plot_fig_num = 6;
tom@455 59
dicklyon@504 60 for n_ears = 1:2
dicklyon@500 61
dicklyon@500 62 CF_struct = CARFAC_Design(n_ears); % default design
dicklyon@502 63
dicklyon@498 64 if n_ears == 2
dicklyon@498 65 % For the 2-channel pass, add a silent second channel:
dicklyon@498 66 test_signal = [test_signal, zeros(size(test_signal))];
dicklyon@498 67 end
dicklyon@498 68
dicklyon@500 69 CF_struct = CARFAC_Init(CF_struct);
dicklyon@502 70
dicklyon@502 71 [CF_struct, nap_decim, nap, BM, ohc, agc] = CARFAC_Run(CF_struct, test_signal, ...
dicklyon@473 72 agc_plot_fig_num);
dicklyon@502 73
dicklyon@502 74 % nap = deskew(nap); % deskew doesn't make much difference
dicklyon@502 75
dicklyon@502 76 % dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 20:50, :).^2));
dicklyon@504 77 sm_BM = filter(1, [1, -0.995], BM(:, :, :).^2);
dicklyon@502 78
dicklyon@498 79 % only ear 1:
dicklyon@504 80 smoothed = sm_BM(100:100:end, :, 1);
dicklyon@504 81 MultiScaleSmooth(10/log(10) * log(smoothed), 1);
dicklyon@502 82
dicklyon@504 83
dicklyon@473 84 % Display results for 1 or 2 ears:
dicklyon@473 85 for ear = 1:n_ears
dicklyon@473 86 smooth_nap = nap_decim(:, :, ear);
dicklyon@473 87 if n_ears == 1
tom@455 88 mono_max = max(smooth_nap(:));
tom@455 89 end
dicklyon@473 90 figure(3 + ear + n_ears) % Makes figures 5, ...
tom@455 91 image(63 * ((max(0, smooth_nap)/mono_max)' .^ 0.5))
tom@455 92 title('smooth nap from nap decim')
tom@455 93 colormap(1 - gray);
tom@455 94 end
dicklyon@502 95
tom@455 96 % Show resulting data, even though M-Lint complains:
tom@455 97 CF_struct
dicklyon@502 98 CF_struct.ears(1).CAR_state
dicklyon@502 99 CF_struct.ears(1).AGC_state
tom@455 100 min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
dicklyon@502 101
tom@455 102 end
tom@455 103
tom@455 104 % Expected result: Figure 3 looks like figure 2, a tiny bit darker.
tom@455 105 % and figure 4 is empty (all zero)