annotate trunk/matlab/bmm/carfac/CARFAC_hacking.m @ 696:d8a404fbc4df

Rename variables to be consistent with the rest of the library.
author ronw@google.com
date Thu, 27 Jun 2013 15:30:46 +0000
parents 2767ce76a1b0
children
rev   line source
tom@574 1 % Copyright 2012 Google Inc. All Rights Reserved.
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@565 25
dicklyon@617 26 use_wav_file = 1;
dicklyon@617 27 dB_list = -40; % -60:20:40
dicklyon@565 28
dicklyon@617 29 if use_wav_file
dicklyon@617 30 wav_fn = 'plan.wav';
dicklyon@536 31
dicklyon@617 32 wav_fn
dicklyon@617 33 file_signal = wavread(wav_fn);
dicklyon@617 34 file_signal = file_signal(:, 1); % Mono test only.
dicklyon@536 35 else
dicklyon@617 36 % A tone complex.
dicklyon@565 37 flist = 1400 + (1:4)*200;
dicklyon@565 38 alist = [1, 1, 1, 1];
dicklyon@563 39 sine_signal = 0;
dicklyon@565 40 times = (0:9999)' / 22050;
dicklyon@563 41 for fno = 1:length(flist)
dicklyon@563 42 sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times);
dicklyon@563 43 end
dicklyon@563 44 growth_power = 0; % use 0 for flat, 4 or more for near exponential
dicklyon@563 45 file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power);
dicklyon@536 46 end
tom@516 47
tom@516 48 % make a long test signal by repeating at different levels:
dicklyon@563 49 % dB = dB_list(1);
dicklyon@563 50 % test_signal = 10^(dB/20)* file_signal(1:4000) % lead-in [];
dicklyon@563 51 test_signal = [];
dicklyon@563 52 for dB = dB_list
tom@516 53 test_signal = [test_signal; file_signal * 10^(dB/20)];
tom@516 54 end
tom@516 55
tom@516 56 %% Run mono, then stereo test:
tom@516 57
tom@516 58 agc_plot_fig_num = 6;
tom@516 59
dicklyon@565 60 for n_ears = 1:2
dicklyon@561 61
dicklyon@561 62 CF_struct = CARFAC_Design(n_ears); % default design
dicklyon@563 63
dicklyon@559 64 if n_ears == 2
dicklyon@559 65 % For the 2-channel pass, add a silent second channel:
dicklyon@559 66 test_signal = [test_signal, zeros(size(test_signal))];
dicklyon@559 67 end
dicklyon@559 68
dicklyon@561 69 CF_struct = CARFAC_Init(CF_struct);
dicklyon@563 70
dicklyon@617 71 [CF_struct, nap_decim, nap] = CARFAC_Run(CF_struct, test_signal, ...
dicklyon@534 72 agc_plot_fig_num);
dicklyon@617 73
dicklyon@617 74 smoothed = filter(1, [1, -0.995], nap(:, :, :));
dicklyon@563 75
dicklyon@559 76 % only ear 1:
dicklyon@617 77 smoothed = max(0, smoothed(50:50:end, :, 1));
dicklyon@617 78 MultiScaleSmooth(smoothed.^0.5, 1);
dicklyon@563 79
dicklyon@617 80 figure(1)
dicklyon@617 81 starti = 0; % Adjust if you want to plot a later part.
dicklyon@617 82 imagesc(nap(starti+(1:15000), :)');
dicklyon@617 83
dicklyon@534 84 % Display results for 1 or 2 ears:
dicklyon@534 85 for ear = 1:n_ears
dicklyon@534 86 smooth_nap = nap_decim(:, :, ear);
dicklyon@534 87 if n_ears == 1
tom@516 88 mono_max = max(smooth_nap(:));
tom@516 89 end
dicklyon@617 90 figure(3 + ear + n_ears) % Makes figures 5, 6, 7.
tom@516 91 image(63 * ((max(0, smooth_nap)/mono_max)' .^ 0.5))
tom@516 92 title('smooth nap from nap decim')
tom@516 93 colormap(1 - gray);
tom@516 94 end
dicklyon@563 95
tom@516 96 % Show resulting data, even though M-Lint complains:
tom@516 97 CF_struct
dicklyon@563 98 CF_struct.ears(1).CAR_state
dicklyon@563 99 CF_struct.ears(1).AGC_state
tom@516 100 min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
dicklyon@563 101
tom@516 102 end
tom@516 103
tom@516 104 % Expected result: Figure 3 looks like figure 2, a tiny bit darker.
tom@516 105 % and figure 4 is empty (all zero)