annotate trunk/matlab/bmm/carfac/CARFAC_Run_Linear.m @ 561:3dff17554c6d

add an ears array level everywhere
author dicklyon@google.com
date Mon, 23 Apr 2012 22:58:40 +0000
parents 335cbd90cc10
children 3e2e0ab4f708
rev   line source
dicklyon@528 1 % Copyright 2012, Google, Inc.
dicklyon@528 2 % Author Richard F. Lyon
dicklyon@528 3 %
dicklyon@528 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@528 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@528 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@528 7 %
dicklyon@528 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@528 9 % you may not use this file except in compliance with the License.
dicklyon@528 10 % You may obtain a copy of the License at
dicklyon@528 11 %
dicklyon@528 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@528 13 %
dicklyon@528 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@528 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@528 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@528 17 % See the License for the specific language governing permissions and
dicklyon@528 18 % limitations under the License.
dicklyon@528 19
dicklyon@528 20 function [naps, CF] = CARFAC_Run_Linear(CF, input_waves, extra_damping)
dicklyon@528 21 % function [naps, CF] = CARFAC_Run_Linear(CF, input_waves, extra_damping)
dicklyon@528 22 %
dicklyon@528 23 % This function runs the CARFAC; that is, filters a 1 or more channel
dicklyon@528 24 % sound input to make one or more neural activity patterns (naps);
dicklyon@528 25 % however, unlike CARFAC_Run, it forces it to be linear, and gives a
dicklyon@528 26 % linear (not detected) output.
dicklyon@528 27
dicklyon@561 28 % only saving one of these, really:
dicklyon@561 29 saved_v_damp_max = CF.ears(1).CAR_coeffs.v_damp_max;
dicklyon@561 30 for ear = 1:CF.n_ears
dicklyon@561 31 CF.ears(ear).CAR_coeffs.v_damp_max = 0.00; % make it linear for now
dicklyon@561 32 end
dicklyon@528 33
dicklyon@534 34 [n_samp, n_ears] = size(input_waves);
dicklyon@528 35 n_ch = CF.n_ch;
dicklyon@528 36
dicklyon@553 37 if nargin < 3
dicklyon@553 38 extra_damping = 0;
dicklyon@553 39 end
dicklyon@553 40
dicklyon@534 41 if n_ears ~= CF.n_ears
dicklyon@528 42 error('bad number of input_waves channels passed to CARFAC_Run')
dicklyon@528 43 end
dicklyon@528 44
dicklyon@534 45 for ear = 1:CF.n_ears
dicklyon@530 46 % Set the state of damping, and prevent interpolation from there:
dicklyon@561 47 CF.ears(ear).CAR_state.zB_memory(:) = extra_damping; % interpolator state
dicklyon@561 48 CF.ears(ear).CAR_state.dzB_memory(:) = 0; % interpolator slope
dicklyon@561 49 CF.ears(ear).CAR_state.g_memory = CARFAC_Stage_g( ...
dicklyon@561 50 CF.ears(ear).CAR_coeffs(ear), extra_damping);
dicklyon@561 51 CF.ears(ear).CAR_state.dg_memory(:) = 0; % interpolator slope
dicklyon@528 52 end
dicklyon@528 53
dicklyon@534 54 naps = zeros(n_samp, n_ch, n_ears);
dicklyon@528 55
dicklyon@528 56 for k = 1:n_samp
dicklyon@528 57 % at each time step, possibly handle multiple channels
dicklyon@534 58 for ear = 1:n_ears
dicklyon@561 59 [filters_out, CF.ears(ear).CAR_state] = CARFAC_CAR_Step( ...
dicklyon@561 60 input_waves(k, ear), CF.ears(ear).CAR_coeffs, CF.ears(ear).CAR_state);
dicklyon@534 61 naps(k, :, ear) = filters_out; % linear
dicklyon@528 62 end
dicklyon@528 63 % skip IHC and AGC updates
dicklyon@528 64 end
dicklyon@528 65
dicklyon@561 66 for ear = 1:CF.n_ears
dicklyon@561 67 CF.ears(ear).CAR_coeffs.v_damp_max = saved_v_damp_max;
dicklyon@561 68 end
dicklyon@528 69