annotate matlab/bmm/carfac/CARFAC_Init.m @ 611:0fbaf443ec82

Carfac C++ revision 3, indluding more style improvements. The output structs are now classes again, and have separate storage methods for each output structure along with flags in the Run and RunSegment methods to allow for only storing NAPs if desired.
author alexbrandmeyer
date Fri, 17 May 2013 19:52:45 +0000
parents 03c642677954
children b3118c9ed67f
rev   line source
tom@455 1 % Copyright 2012, Google, Inc.
tom@455 2 % Author: Richard F. Lyon
tom@455 3 %
tom@455 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
tom@455 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
tom@455 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
tom@455 7 %
tom@455 8 % Licensed under the Apache License, Version 2.0 (the "License");
tom@455 9 % you may not use this file except in compliance with the License.
tom@455 10 % You may obtain a copy of the License at
tom@455 11 %
tom@455 12 % http://www.apache.org/licenses/LICENSE-2.0
tom@455 13 %
tom@455 14 % Unless required by applicable law or agreed to in writing, software
tom@455 15 % distributed under the License is distributed on an "AS IS" BASIS,
tom@455 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tom@455 17 % See the License for the specific language governing permissions and
tom@455 18 % limitations under the License.
tom@455 19
dicklyon@500 20 function CF = CARFAC_Init(CF)
dicklyon@500 21 % function CF = CARFAC_Init(CF)
tom@455 22 %
dicklyon@500 23 % Initialize state for one or more ears of CF.
dicklyon@500 24 % This allocates and zeros all the state vector storage in the CF struct.
tom@455 25
dicklyon@500 26 n_ears = CF.n_ears;
tom@455 27
dicklyon@473 28 for ear = 1:n_ears
dicklyon@473 29 % for now there's only one coeffs, not one per ear
dicklyon@500 30 CF.ears(ear).CAR_state = CAR_Init_State(CF.ears(ear).CAR_coeffs);
dicklyon@500 31 CF.ears(ear).IHC_state = IHC_Init_State(CF.ears(ear).IHC_coeffs);
dicklyon@500 32 CF.ears(ear).AGC_state = AGC_Init_State(CF.ears(ear).AGC_coeffs);
dicklyon@473 33 end
dicklyon@462 34
dicklyon@473 35
dicklyon@473 36 function state = CAR_Init_State(coeffs)
dicklyon@473 37 n_ch = coeffs.n_ch;
dicklyon@473 38 state = struct( ...
dicklyon@473 39 'z1_memory', zeros(n_ch, 1), ...
dicklyon@473 40 'z2_memory', zeros(n_ch, 1), ...
dicklyon@473 41 'zA_memory', zeros(n_ch, 1), ...
dicklyon@606 42 'zB_memory', coeffs.zr_coeffs, ...
dicklyon@473 43 'dzB_memory', zeros(n_ch, 1), ...
dicklyon@473 44 'zY_memory', zeros(n_ch, 1), ...
dicklyon@473 45 'g_memory', coeffs.g0_coeffs, ...
dicklyon@473 46 'dg_memory', zeros(n_ch, 1) ...
dicklyon@473 47 );
dicklyon@473 48
dicklyon@473 49
dicklyon@473 50 function state = AGC_Init_State(coeffs)
dicklyon@473 51 n_ch = coeffs.n_ch;
dicklyon@473 52 n_AGC_stages = coeffs.n_AGC_stages;
dicklyon@473 53 state = struct( ...
dicklyon@473 54 'AGC_memory', zeros(n_ch, n_AGC_stages), ...
dicklyon@473 55 'input_accum', zeros(n_ch, n_AGC_stages), ...
dicklyon@473 56 'decim_phase', zeros(n_AGC_stages, 1) ... % integer decimator phase
dicklyon@473 57 );
dicklyon@473 58
dicklyon@473 59
dicklyon@473 60 function state = IHC_Init_State(coeffs)
dicklyon@473 61 n_ch = coeffs.n_ch;
dicklyon@495 62 if coeffs.just_hwr
dicklyon@495 63 state = struct('ihc_accum', zeros(n_ch, 1));
dicklyon@495 64 else
dicklyon@495 65 if coeffs.one_cap
dicklyon@495 66 state = struct( ...
dicklyon@495 67 'ihc_accum', zeros(n_ch, 1), ...
dicklyon@495 68 'cap_voltage', coeffs.rest_cap * ones(n_ch, 1), ...
dicklyon@495 69 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 70 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 71 'ac_coupler', zeros(n_ch, 1) ...
dicklyon@495 72 );
dicklyon@495 73 else
dicklyon@495 74 state = struct( ...
dicklyon@495 75 'ihc_accum', zeros(n_ch, 1), ...
dicklyon@495 76 'cap1_voltage', coeffs.rest_cap1 * ones(n_ch, 1), ...
dicklyon@495 77 'cap2_voltage', coeffs.rest_cap2* ones(n_ch, 1), ...
dicklyon@495 78 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 79 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 80 'ac_coupler', zeros(n_ch, 1) ...
dicklyon@495 81 );
dicklyon@495 82 end
dicklyon@495 83 end
dicklyon@473 84
dicklyon@495 85
dicklyon@495 86