annotate trunk/matlab/bmm/carfac/CARFAC_Init.m @ 617:2767ce76a1b0

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