annotate matlab/bmm/carfac/CARFAC_Run_Linear.m @ 655:8a2b0cbd7a64

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