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: tom@455: function [ihc_out, state] = CARFAC_IHCStep(filters_out, coeffs, state); tom@455: % function [ihc_out, state] = CARFAC_IHCStep(filters_out, coeffs, state); tom@455: % tom@455: % One sample-time update of inner-hair-cell (IHC) model, including the tom@455: % detection nonlinearity and one or two capacitor state variables. tom@455: tom@455: just_hwr = coeffs.just_hwr; tom@455: tom@455: if just_hwr tom@455: ihc_out = max(0, filters_out); dicklyon@462: state.ihc_accum = state.ihc_accum + ihc_out; tom@455: else tom@455: one_cap = coeffs.one_cap; tom@455: dicklyon@462: detect = CARFAC_Detect(filters_out); % detect with HWR or so tom@455: tom@455: if one_cap tom@455: ihc_out = detect .* state.cap_voltage; tom@455: state.cap_voltage = state.cap_voltage - ihc_out .* coeffs.out_rate + ... tom@455: (1 - state.cap_voltage) .* coeffs.in_rate; tom@455: else tom@455: % change to 2-cap version more like Meddis's: tom@455: ihc_out = detect .* state.cap2_voltage; tom@455: state.cap1_voltage = state.cap1_voltage - ... tom@455: (state.cap1_voltage - state.cap2_voltage) .* coeffs.out1_rate + ... tom@455: (1 - state.cap1_voltage) .* coeffs.in1_rate; tom@455: tom@455: state.cap2_voltage = state.cap2_voltage - ihc_out .* coeffs.out2_rate + ... tom@455: (state.cap1_voltage - state.cap2_voltage) .* coeffs.in2_rate; tom@455: end tom@455: tom@455: % smooth it twice with LPF: tom@455: tom@455: state.lpf1_state = state.lpf1_state + coeffs.lpf_coeff * ... tom@455: (ihc_out - state.lpf1_state); tom@455: tom@455: state.lpf2_state = state.lpf2_state + coeffs.lpf_coeff * ... tom@455: (state.lpf1_state - state.lpf2_state); tom@455: dicklyon@462: ihc_out = state.lpf2_state - coeffs.rest_output; tom@455: dicklyon@462: state.ihc_accum = state.ihc_accum + max(0, ihc_out); tom@455: end