annotate trunk/matlab/bmm/carfac/CARFAC_hacking.m @ 518:62c2f21d7a75

add sample data file plan.wav
author dicklyon@google.com
date Thu, 16 Feb 2012 19:07:18 +0000
parents aa282a2b61bb
children 741187dc780f
rev   line source
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 %%
tom@516 25 file_signal = wavread('plan.wav');
tom@516 26
tom@516 27 % file_signal = file_signal(9000+(1:10000)); % trim for a faster test
tom@516 28 file_signal = file_signal(9300+(1:5000)); % trim for a faster test
tom@516 29
tom@516 30 % repeat with negated signal to compare responses:
dicklyon@517 31 % file_signal = [file_signal; -file_signal];
tom@516 32
tom@516 33 % make a long test signal by repeating at different levels:
tom@516 34 test_signal = [];
dicklyon@517 35 for dB = -40:20:0 % -60:20:40 % -80:20:60
tom@516 36 test_signal = [test_signal; file_signal * 10^(dB/20)];
tom@516 37 end
tom@516 38
tom@516 39 %%
tom@516 40 CF_struct = CARFAC_Design; % default design
tom@516 41
tom@516 42 %% Run mono, then stereo test:
tom@516 43
tom@516 44 agc_plot_fig_num = 6;
tom@516 45
dicklyon@517 46 for n_mics = 1:2
tom@516 47 CF_struct = CARFAC_Init(CF_struct, n_mics);
tom@516 48
tom@516 49 [nap, CF_struct, nap_decim] = CARFAC_Run(CF_struct, ...
tom@516 50 test_signal, agc_plot_fig_num);
tom@516 51
tom@516 52 % nap = deskew(nap); % deskew doesn't make much difference
tom@516 53
dicklyon@517 54 if n_mics == 1 % because this hack doesn't work for binarual yet
dicklyon@517 55 MultiScaleSmooth(nap_decim, 10);
dicklyon@517 56 end
tom@516 57
tom@516 58 % nap_decim = nap;
tom@516 59 % nap_decim = smooth1d(nap_decim, 1);
tom@516 60 % nap_decim = nap_decim(1:8:size(nap_decim, 1), :);
tom@516 61
tom@516 62 % Display results for 1 or 2 mics:
tom@516 63 for mic = 1:n_mics
tom@516 64 smooth_nap = nap_decim(:, :, mic);
tom@516 65 if n_mics == 1
tom@516 66 mono_max = max(smooth_nap(:));
tom@516 67 end
tom@516 68 figure(3 + mic + n_mics) % Makes figures 5, ...
tom@516 69 image(63 * ((max(0, smooth_nap)/mono_max)' .^ 0.5))
tom@516 70 title('smooth nap from nap decim')
tom@516 71 colormap(1 - gray);
tom@516 72 end
tom@516 73
tom@516 74 % Show resulting data, even though M-Lint complains:
tom@516 75 CF_struct
tom@516 76 CF_struct.k_mod_decim
tom@516 77 CF_struct.filter_state
tom@516 78 CF_struct.AGC_state
tom@516 79 min_max = [min(nap(:)), max(nap(:))]
tom@516 80 min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
tom@516 81
tom@516 82 % For the 2-channel pass, add a silent second channel:
tom@516 83 test_signal = [test_signal, zeros(size(test_signal))];
tom@516 84 end
tom@516 85
tom@516 86 % Expected result: Figure 3 looks like figure 2, a tiny bit darker.
tom@516 87 % and figure 4 is empty (all zero)