tom@455: % Copyright 2012, Google, Inc. tom@455: % Author: Richard F. Lyon tom@455: % tom@455: % This Matlab file is part of an implementation of Lyon's cochlear model: tom@455: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" tom@455: % to supplement Lyon's upcoming book "Human and Machine Hearing" tom@455: % tom@455: % Licensed under the Apache License, Version 2.0 (the "License"); tom@455: % you may not use this file except in compliance with the License. tom@455: % You may obtain a copy of the License at tom@455: % tom@455: % http://www.apache.org/licenses/LICENSE-2.0 tom@455: % tom@455: % Unless required by applicable law or agreed to in writing, software tom@455: % distributed under the License is distributed on an "AS IS" BASIS, tom@455: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tom@455: % See the License for the specific language governing permissions and tom@455: % limitations under the License. tom@455: dicklyon@500: function CF = CARFAC_Init(CF) dicklyon@500: % function CF = CARFAC_Init(CF) tom@455: % dicklyon@500: % Initialize state for one or more ears of CF. dicklyon@500: % This allocates and zeros all the state vector storage in the CF struct. tom@455: dicklyon@500: n_ears = CF.n_ears; tom@455: dicklyon@473: for ear = 1:n_ears dicklyon@473: % for now there's only one coeffs, not one per ear dicklyon@500: CF.ears(ear).CAR_state = CAR_Init_State(CF.ears(ear).CAR_coeffs); dicklyon@500: CF.ears(ear).IHC_state = IHC_Init_State(CF.ears(ear).IHC_coeffs); dicklyon@500: CF.ears(ear).AGC_state = AGC_Init_State(CF.ears(ear).AGC_coeffs); dicklyon@473: end dicklyon@462: dicklyon@473: dicklyon@473: function state = CAR_Init_State(coeffs) dicklyon@473: n_ch = coeffs.n_ch; dicklyon@473: state = struct( ... dicklyon@473: 'z1_memory', zeros(n_ch, 1), ... dicklyon@473: 'z2_memory', zeros(n_ch, 1), ... dicklyon@473: 'zA_memory', zeros(n_ch, 1), ... dicklyon@473: 'zB_memory', zeros(n_ch, 1), ... dicklyon@473: 'dzB_memory', zeros(n_ch, 1), ... dicklyon@473: 'zY_memory', zeros(n_ch, 1), ... dicklyon@473: 'g_memory', coeffs.g0_coeffs, ... dicklyon@473: 'dg_memory', zeros(n_ch, 1) ... dicklyon@473: ); dicklyon@473: dicklyon@473: dicklyon@473: function state = AGC_Init_State(coeffs) dicklyon@473: n_ch = coeffs.n_ch; dicklyon@473: n_AGC_stages = coeffs.n_AGC_stages; dicklyon@473: state = struct( ... dicklyon@473: 'AGC_memory', zeros(n_ch, n_AGC_stages), ... dicklyon@473: 'input_accum', zeros(n_ch, n_AGC_stages), ... dicklyon@473: 'decim_phase', zeros(n_AGC_stages, 1) ... % integer decimator phase dicklyon@473: ); dicklyon@473: dicklyon@473: dicklyon@473: function state = IHC_Init_State(coeffs) dicklyon@473: n_ch = coeffs.n_ch; dicklyon@495: if coeffs.just_hwr dicklyon@495: state = struct('ihc_accum', zeros(n_ch, 1)); dicklyon@495: else dicklyon@495: if coeffs.one_cap dicklyon@495: state = struct( ... dicklyon@495: 'ihc_accum', zeros(n_ch, 1), ... dicklyon@495: 'cap_voltage', coeffs.rest_cap * ones(n_ch, 1), ... dicklyon@495: 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ... dicklyon@504: 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ... dicklyon@504: 'ac_coupler', zeros(n_ch, 1) ... dicklyon@495: ); dicklyon@495: else dicklyon@495: state = struct( ... dicklyon@495: 'ihc_accum', zeros(n_ch, 1), ... dicklyon@495: 'cap1_voltage', coeffs.rest_cap1 * ones(n_ch, 1), ... dicklyon@495: 'cap2_voltage', coeffs.rest_cap2* ones(n_ch, 1), ... dicklyon@495: 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ... dicklyon@504: 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ... dicklyon@504: 'ac_coupler', zeros(n_ch, 1) ... dicklyon@495: ); dicklyon@495: end dicklyon@495: end dicklyon@473: dicklyon@495: dicklyon@495: