annotate matlab/bmm/carfac/CARFAC_hacking.m @ 501:a4353a6d8241

Fixed ffmpeg frame-rate bug
author tomwalters@google.com
date Tue, 01 May 2012 23:32:24 +0000
parents 896620d9d539
children 37c007925536
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@498 25 use_plan_file = 1;
dicklyon@475 26 if use_plan_file
dicklyon@475 27
dicklyon@475 28 file_signal = wavread('plan.wav');
dicklyon@475 29 file_signal = file_signal(8100+(1:20000)); % trim for a faster test
dicklyon@475 30
dicklyon@475 31 else
dicklyon@475 32 flist = [1000];
dicklyon@475 33 alist = [1];
dicklyon@475 34 flist = 1000;
dicklyon@475 35 alist = 1;
dicklyon@475 36 sine_signal = 0;
dicklyon@475 37 times = (0:19999)' / 22050;
dicklyon@475 38 for fno = 1:length(flist)
dicklyon@475 39 sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times);
dicklyon@475 40 end
dicklyon@475 41 growth_power = 0; % use 0 for flat, 4 or more for near exponential
dicklyon@475 42 file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power);
dicklyon@475 43 end
tom@455 44
tom@455 45 % repeat with negated signal to compare responses:
dicklyon@456 46 % file_signal = [file_signal; -file_signal];
tom@455 47
tom@455 48 % make a long test signal by repeating at different levels:
dicklyon@475 49 dB = -80;
dicklyon@475 50 test_signal = 10^(dB/20)* file_signal(1:4000) % lead-in [];
dicklyon@498 51 for dB = -80:20:60
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@498 60 for n_ears = 1:2
dicklyon@500 61
dicklyon@500 62 CF_struct = CARFAC_Design(n_ears); % default design
dicklyon@500 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);
tom@455 70
dicklyon@475 71 [CF_struct, nap_decim, nap, BM] = CARFAC_Run(CF_struct, test_signal, ...
dicklyon@473 72 agc_plot_fig_num);
tom@455 73
tom@455 74 % nap = deskew(nap); % deskew doesn't make much difference
tom@455 75
dicklyon@475 76 % dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 38:40, :).^2));
dicklyon@475 77 dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 20:50, :).^2));
dicklyon@475 78
dicklyon@498 79 % only ear 1:
dicklyon@498 80 MultiScaleSmooth(dB_BM(5000:200:end, :, 1), 1);
tom@455 81
dicklyon@473 82 % Display results for 1 or 2 ears:
dicklyon@473 83 for ear = 1:n_ears
dicklyon@473 84 smooth_nap = nap_decim(:, :, ear);
dicklyon@473 85 if n_ears == 1
tom@455 86 mono_max = max(smooth_nap(:));
tom@455 87 end
dicklyon@473 88 figure(3 + ear + n_ears) % Makes figures 5, ...
tom@455 89 image(63 * ((max(0, smooth_nap)/mono_max)' .^ 0.5))
tom@455 90 title('smooth nap from nap decim')
tom@455 91 colormap(1 - gray);
tom@455 92 end
tom@455 93
tom@455 94 % Show resulting data, even though M-Lint complains:
tom@455 95 CF_struct
dicklyon@473 96 CF_struct.CAR_state
tom@455 97 CF_struct.AGC_state
tom@455 98 min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
tom@455 99
tom@455 100 end
tom@455 101
tom@455 102 % Expected result: Figure 3 looks like figure 2, a tiny bit darker.
tom@455 103 % and figure 4 is empty (all zero)