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