dicklyon@536: % Copyright 2012, Google, Inc. dicklyon@536: % Author Richard F. Lyon dicklyon@536: % dicklyon@536: % This Matlab file is part of an implementation of Lyon's cochlear model: dicklyon@536: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" dicklyon@536: % to supplement Lyon's upcoming book "Human and Machine Hearing" dicklyon@536: % dicklyon@536: % Licensed under the Apache License, Version 2.0 (the "License"); dicklyon@536: % you may not use this file except in compliance with the License. dicklyon@536: % You may obtain a copy of the License at dicklyon@536: % dicklyon@536: % http://www.apache.org/licenses/LICENSE-2.0 dicklyon@536: % dicklyon@536: % Unless required by applicable law or agreed to in writing, software dicklyon@536: % distributed under the License is distributed on an "AS IS" BASIS, dicklyon@536: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. dicklyon@536: % See the License for the specific language governing permissions and dicklyon@536: % limitations under the License. dicklyon@536: dicklyon@536: function [CF, decim_naps, naps] = CARFAC_Run_Open_Loop ... dicklyon@536: (CF, input_waves, AGC_plot_fig_num) dicklyon@536: % function [CF, decim_naps, naps] = CARFAC_Run_Open_Loop ... dicklyon@536: % (CF, input_waves, AGC_plot_fig_num) dicklyon@536: % dicklyon@536: % Freeze the damping by disabling AGC feedback, and run so we can dicklyon@536: % see what the filters and AGC do in that frozen state. And zap the dicklyon@536: % stage gain in the AGC so we can see the state filters without combining dicklyon@536: % them. dicklyon@536: dicklyon@536: [n_samp, n_ears] = size(input_waves); dicklyon@536: n_ch = CF.n_ch; dicklyon@536: dicklyon@536: if nargin < 3 dicklyon@536: AGC_plot_fig_num = 0; dicklyon@536: end dicklyon@536: dicklyon@536: if n_ears ~= CF.n_ears dicklyon@536: error('bad number of input_waves channels passed to CARFAC_Run') dicklyon@536: end dicklyon@536: dicklyon@536: dicklyon@536: naps = zeros(n_samp, n_ch, n_ears); dicklyon@536: dicklyon@536: seglen = 16; dicklyon@536: n_segs = ceil(n_samp / seglen); dicklyon@536: dicklyon@536: if nargout > 1 dicklyon@536: % make decimated detect output: dicklyon@536: decim_naps = zeros(n_segs, CF.n_ch, CF.n_ears); dicklyon@536: else dicklyon@536: decim_naps = []; dicklyon@536: end dicklyon@536: dicklyon@536: if nargout > 2 dicklyon@536: % make decimated detect output: dicklyon@536: naps = zeros(n_samp, CF.n_ch, CF.n_ears); dicklyon@536: else dicklyon@536: naps = []; dicklyon@536: end dicklyon@536: dicklyon@536: % zero the deltas: dicklyon@536: for ear = 1:CF.n_ears dicklyon@536: CF.CAR_state(ear).dzB_memory = 0; dicklyon@536: CF.CAR_state(ear).dg_memory = 0; dicklyon@536: end dicklyon@536: open_loop = 1; dicklyon@536: CF.AGC_coeffs.AGC_stage_gain = 0; % HACK to see the stages separately dicklyon@536: dicklyon@536: smoothed_state = 0; dicklyon@536: dicklyon@536: for seg_num = 1:n_segs dicklyon@536: if seg_num == n_segs dicklyon@536: % The last segement may be short of seglen, but do it anyway: dicklyon@536: k_range = (seglen*(seg_num - 1) + 1):n_samp; dicklyon@536: else dicklyon@536: k_range = seglen*(seg_num - 1) + (1:seglen); dicklyon@536: end dicklyon@536: % Process a segment to get a slice of decim_naps, and plot AGC state: dicklyon@536: [seg_naps, CF] = CARFAC_Run_Segment(CF, input_waves(k_range, :), ... dicklyon@536: open_loop); dicklyon@536: dicklyon@536: if ~isempty(naps) dicklyon@536: for ear = 1:n_ears dicklyon@536: % Accumulate segment naps to make full naps dicklyon@536: naps(k_range, :, ear) = seg_naps(:, :, ear); dicklyon@536: end dicklyon@536: end dicklyon@536: dicklyon@536: if ~isempty(decim_naps) dicklyon@536: for ear = 1:n_ears dicklyon@536: decim_naps(seg_num, :, ear) = CF.IHC_state(ear).ihc_accum / seglen; dicklyon@536: CF.IHC_state(ear).ihc_accum = zeros(n_ch,1); dicklyon@536: end dicklyon@536: end dicklyon@536: dicklyon@536: if AGC_plot_fig_num dicklyon@536: figure(AGC_plot_fig_num); hold off; clf dicklyon@536: set(gca, 'Position', [.25, .25, .5, .5]) dicklyon@536: smoothed_state = (3*smoothed_state + CF.AGC_state(1).AGC_memory) / 4; dicklyon@536: for ear = 1 dicklyon@536: total_state = 0; dicklyon@536: for stage = 1:4; dicklyon@536: weighted_state = smoothed_state(:, stage) * 2^(stage-1); dicklyon@536: plot(weighted_state, 'k-', 'LineWidth', 0.4); dicklyon@536: hold on dicklyon@536: total_state = total_state + weighted_state; dicklyon@536: end dicklyon@536: maxes(ear) = max(total_state); dicklyon@536: plot(total_state, 'k-', 'LineWidth', 1.1) dicklyon@536: end dicklyon@536: dicklyon@536: axis([0, CF.n_ch+1, 0.0, max(maxes) * 1.01 + 0.002]); dicklyon@536: drawnow dicklyon@536: end dicklyon@536: dicklyon@536: end dicklyon@536: dicklyon@536: dicklyon@536: