tom@574: % Copyright 2012 Google Inc. All Rights Reserved. tom@516: % Author: Richard F. Lyon tom@516: % tom@516: % This Matlab file is part of an implementation of Lyon's cochlear model: tom@516: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" tom@516: % to supplement Lyon's upcoming book "Human and Machine Hearing" tom@516: % tom@516: % Licensed under the Apache License, Version 2.0 (the "License"); tom@516: % you may not use this file except in compliance with the License. tom@516: % You may obtain a copy of the License at tom@516: % tom@516: % http://www.apache.org/licenses/LICENSE-2.0 tom@516: % tom@516: % Unless required by applicable law or agreed to in writing, software tom@516: % distributed under the License is distributed on an "AS IS" BASIS, tom@516: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tom@516: % See the License for the specific language governing permissions and tom@516: % limitations under the License. tom@516: tom@516: %% Test/demo hacking for CARFAC Matlab stuff: tom@516: tom@516: clear variables tom@516: tom@516: %% dicklyon@565: dicklyon@559: use_plan_file = 1; dicklyon@565: dB_list = -60:20:40 dicklyon@565: dicklyon@536: if use_plan_file dicklyon@536: dicklyon@536: file_signal = wavread('plan.wav'); dicklyon@563: % file_signal = file_signal(8100+(1:20000)); % trim for a faster test dicklyon@563: file_signal = file_signal(10000+(1:10000)); % trim for a faster test dicklyon@536: dicklyon@536: else dicklyon@565: flist = 1400 + (1:4)*200; dicklyon@565: alist = [1, 1, 1, 1]; dicklyon@563: sine_signal = 0; dicklyon@565: times = (0:9999)' / 22050; dicklyon@563: for fno = 1:length(flist) dicklyon@563: sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times); dicklyon@563: end dicklyon@563: growth_power = 0; % use 0 for flat, 4 or more for near exponential dicklyon@563: file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power); dicklyon@536: end tom@516: tom@516: % make a long test signal by repeating at different levels: dicklyon@563: % dB = dB_list(1); dicklyon@563: % test_signal = 10^(dB/20)* file_signal(1:4000) % lead-in []; dicklyon@563: test_signal = []; dicklyon@563: for dB = dB_list tom@516: test_signal = [test_signal; file_signal * 10^(dB/20)]; tom@516: end tom@516: tom@516: tom@516: %% Run mono, then stereo test: tom@516: tom@516: agc_plot_fig_num = 6; tom@516: dicklyon@565: for n_ears = 1:2 dicklyon@561: dicklyon@561: CF_struct = CARFAC_Design(n_ears); % default design dicklyon@563: dicklyon@559: if n_ears == 2 dicklyon@559: % For the 2-channel pass, add a silent second channel: dicklyon@559: test_signal = [test_signal, zeros(size(test_signal))]; dicklyon@559: end dicklyon@559: dicklyon@561: CF_struct = CARFAC_Init(CF_struct); dicklyon@563: dicklyon@563: [CF_struct, nap_decim, nap, BM, ohc, agc] = CARFAC_Run(CF_struct, test_signal, ... dicklyon@534: agc_plot_fig_num); dicklyon@563: dicklyon@563: % nap = deskew(nap); % deskew doesn't make much difference dicklyon@563: dicklyon@563: % dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 20:50, :).^2)); dicklyon@565: sm_BM = filter(1, [1, -0.995], BM(:, :, :).^2); dicklyon@563: dicklyon@559: % only ear 1: dicklyon@565: smoothed = sm_BM(100:100:end, :, 1); dicklyon@565: MultiScaleSmooth(10/log(10) * log(smoothed), 1); dicklyon@563: dicklyon@565: dicklyon@534: % Display results for 1 or 2 ears: dicklyon@534: for ear = 1:n_ears dicklyon@534: smooth_nap = nap_decim(:, :, ear); dicklyon@534: if n_ears == 1 tom@516: mono_max = max(smooth_nap(:)); tom@516: end dicklyon@534: figure(3 + ear + n_ears) % Makes figures 5, ... tom@516: image(63 * ((max(0, smooth_nap)/mono_max)' .^ 0.5)) tom@516: title('smooth nap from nap decim') tom@516: colormap(1 - gray); tom@516: end dicklyon@563: tom@516: % Show resulting data, even though M-Lint complains: tom@516: CF_struct dicklyon@563: CF_struct.ears(1).CAR_state dicklyon@563: CF_struct.ears(1).AGC_state tom@516: min_max_decim = [min(nap_decim(:)), max(nap_decim(:))] dicklyon@563: tom@516: end tom@516: tom@516: % Expected result: Figure 3 looks like figure 2, a tiny bit darker. tom@516: % and figure 4 is empty (all zero)