annotate trunk/matlab/bmm/carfac/CARFAC_Run_Open_Loop.m @ 548:ff12d0432d9c

Implemented all but g0 initialisation in CAR class
author Ulf.Hammarqvist@gmail.com
date Sat, 07 Apr 2012 09:35:10 +0000
parents 2964a3b4a00a
children
rev   line source
dicklyon@536 1 % Copyright 2012, Google, Inc.
dicklyon@536 2 % Author Richard F. Lyon
dicklyon@536 3 %
dicklyon@536 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@536 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@536 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@536 7 %
dicklyon@536 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@536 9 % you may not use this file except in compliance with the License.
dicklyon@536 10 % You may obtain a copy of the License at
dicklyon@536 11 %
dicklyon@536 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@536 13 %
dicklyon@536 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@536 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@536 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@536 17 % See the License for the specific language governing permissions and
dicklyon@536 18 % limitations under the License.
dicklyon@536 19
dicklyon@536 20 function [CF, decim_naps, naps] = CARFAC_Run_Open_Loop ...
dicklyon@536 21 (CF, input_waves, AGC_plot_fig_num)
dicklyon@536 22 % function [CF, decim_naps, naps] = CARFAC_Run_Open_Loop ...
dicklyon@536 23 % (CF, input_waves, AGC_plot_fig_num)
dicklyon@536 24 %
dicklyon@536 25 % Freeze the damping by disabling AGC feedback, and run so we can
dicklyon@536 26 % see what the filters and AGC do in that frozen state. And zap the
dicklyon@536 27 % stage gain in the AGC so we can see the state filters without combining
dicklyon@536 28 % them.
dicklyon@536 29
dicklyon@536 30 [n_samp, n_ears] = size(input_waves);
dicklyon@536 31 n_ch = CF.n_ch;
dicklyon@536 32
dicklyon@536 33 if nargin < 3
dicklyon@536 34 AGC_plot_fig_num = 0;
dicklyon@536 35 end
dicklyon@536 36
dicklyon@536 37 if n_ears ~= CF.n_ears
dicklyon@536 38 error('bad number of input_waves channels passed to CARFAC_Run')
dicklyon@536 39 end
dicklyon@536 40
dicklyon@536 41
dicklyon@536 42 naps = zeros(n_samp, n_ch, n_ears);
dicklyon@536 43
dicklyon@536 44 seglen = 16;
dicklyon@536 45 n_segs = ceil(n_samp / seglen);
dicklyon@536 46
dicklyon@536 47 if nargout > 1
dicklyon@536 48 % make decimated detect output:
dicklyon@536 49 decim_naps = zeros(n_segs, CF.n_ch, CF.n_ears);
dicklyon@536 50 else
dicklyon@536 51 decim_naps = [];
dicklyon@536 52 end
dicklyon@536 53
dicklyon@536 54 if nargout > 2
dicklyon@536 55 % make decimated detect output:
dicklyon@536 56 naps = zeros(n_samp, CF.n_ch, CF.n_ears);
dicklyon@536 57 else
dicklyon@536 58 naps = [];
dicklyon@536 59 end
dicklyon@536 60
dicklyon@536 61 % zero the deltas:
dicklyon@536 62 for ear = 1:CF.n_ears
dicklyon@536 63 CF.CAR_state(ear).dzB_memory = 0;
dicklyon@536 64 CF.CAR_state(ear).dg_memory = 0;
dicklyon@536 65 end
dicklyon@536 66 open_loop = 1;
dicklyon@536 67 CF.AGC_coeffs.AGC_stage_gain = 0; % HACK to see the stages separately
dicklyon@536 68
dicklyon@536 69 smoothed_state = 0;
dicklyon@536 70
dicklyon@536 71 for seg_num = 1:n_segs
dicklyon@536 72 if seg_num == n_segs
dicklyon@536 73 % The last segement may be short of seglen, but do it anyway:
dicklyon@536 74 k_range = (seglen*(seg_num - 1) + 1):n_samp;
dicklyon@536 75 else
dicklyon@536 76 k_range = seglen*(seg_num - 1) + (1:seglen);
dicklyon@536 77 end
dicklyon@536 78 % Process a segment to get a slice of decim_naps, and plot AGC state:
dicklyon@536 79 [seg_naps, CF] = CARFAC_Run_Segment(CF, input_waves(k_range, :), ...
dicklyon@536 80 open_loop);
dicklyon@536 81
dicklyon@536 82 if ~isempty(naps)
dicklyon@536 83 for ear = 1:n_ears
dicklyon@536 84 % Accumulate segment naps to make full naps
dicklyon@536 85 naps(k_range, :, ear) = seg_naps(:, :, ear);
dicklyon@536 86 end
dicklyon@536 87 end
dicklyon@536 88
dicklyon@536 89 if ~isempty(decim_naps)
dicklyon@536 90 for ear = 1:n_ears
dicklyon@536 91 decim_naps(seg_num, :, ear) = CF.IHC_state(ear).ihc_accum / seglen;
dicklyon@536 92 CF.IHC_state(ear).ihc_accum = zeros(n_ch,1);
dicklyon@536 93 end
dicklyon@536 94 end
dicklyon@536 95
dicklyon@536 96 if AGC_plot_fig_num
dicklyon@536 97 figure(AGC_plot_fig_num); hold off; clf
dicklyon@536 98 set(gca, 'Position', [.25, .25, .5, .5])
dicklyon@536 99 smoothed_state = (3*smoothed_state + CF.AGC_state(1).AGC_memory) / 4;
dicklyon@536 100 for ear = 1
dicklyon@536 101 total_state = 0;
dicklyon@536 102 for stage = 1:4;
dicklyon@536 103 weighted_state = smoothed_state(:, stage) * 2^(stage-1);
dicklyon@536 104 plot(weighted_state, 'k-', 'LineWidth', 0.4);
dicklyon@536 105 hold on
dicklyon@536 106 total_state = total_state + weighted_state;
dicklyon@536 107 end
dicklyon@536 108 maxes(ear) = max(total_state);
dicklyon@536 109 plot(total_state, 'k-', 'LineWidth', 1.1)
dicklyon@536 110 end
dicklyon@536 111
dicklyon@536 112 axis([0, CF.n_ch+1, 0.0, max(maxes) * 1.01 + 0.002]);
dicklyon@536 113 drawnow
dicklyon@536 114 end
dicklyon@536 115
dicklyon@536 116 end
dicklyon@536 117
dicklyon@536 118
dicklyon@536 119