annotate matlab/bmm/carfac/CARFAC_Init.m @ 623:b3118c9ed67f

Turn the AGC coeffs inside out: array of structs instead of a struct of little arrays. In C++ use a vector<AGC_coeffs> for this; each of 4 stages has an entry; many fewer places need to do indexing by stage, and this removes the temptation to use little eigen arrays for the 4 stages. Also latest version of experimental log-lag SAI hacks.
author dicklyon@google.com
date Tue, 21 May 2013 04:24:05 +0000
parents 03c642677954
children
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@623 51 n_ch = coeffs(1).n_ch;
dicklyon@623 52 n_AGC_stages = coeffs(1).n_AGC_stages;
dicklyon@623 53 state = struct([]);
dicklyon@623 54 for stage = 1:n_AGC_stages
dicklyon@623 55 % Initialize state recursively...
dicklyon@623 56 state(stage).AGC_memory = zeros(n_ch, 1);
dicklyon@623 57 state(stage).input_accum = zeros(n_ch, 1);
dicklyon@623 58 state(stage).decim_phase = 0; % integer decimator phase
dicklyon@623 59 end
dicklyon@473 60
dicklyon@473 61
dicklyon@473 62 function state = IHC_Init_State(coeffs)
dicklyon@473 63 n_ch = coeffs.n_ch;
dicklyon@495 64 if coeffs.just_hwr
dicklyon@495 65 state = struct('ihc_accum', zeros(n_ch, 1));
dicklyon@495 66 else
dicklyon@495 67 if coeffs.one_cap
dicklyon@495 68 state = struct( ...
dicklyon@495 69 'ihc_accum', zeros(n_ch, 1), ...
dicklyon@495 70 'cap_voltage', coeffs.rest_cap * ones(n_ch, 1), ...
dicklyon@495 71 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 72 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 73 'ac_coupler', zeros(n_ch, 1) ...
dicklyon@495 74 );
dicklyon@495 75 else
dicklyon@495 76 state = struct( ...
dicklyon@495 77 'ihc_accum', zeros(n_ch, 1), ...
dicklyon@495 78 'cap1_voltage', coeffs.rest_cap1 * ones(n_ch, 1), ...
dicklyon@495 79 'cap2_voltage', coeffs.rest_cap2* ones(n_ch, 1), ...
dicklyon@495 80 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 81 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ...
dicklyon@504 82 'ac_coupler', zeros(n_ch, 1) ...
dicklyon@495 83 );
dicklyon@495 84 end
dicklyon@495 85 end
dicklyon@473 86
dicklyon@495 87
dicklyon@495 88