dicklyon@534: % Copyright 2012, Google, Inc. dicklyon@534: % Author: Richard F. Lyon dicklyon@534: % dicklyon@534: % This Matlab file is part of an implementation of Lyon's cochlear model: dicklyon@534: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" dicklyon@534: % to supplement Lyon's upcoming book "Human and Machine Hearing" dicklyon@534: % dicklyon@534: % Licensed under the Apache License, Version 2.0 (the "License"); dicklyon@534: % you may not use this file except in compliance with the License. dicklyon@534: % You may obtain a copy of the License at dicklyon@534: % dicklyon@534: % http://www.apache.org/licenses/LICENSE-2.0 dicklyon@534: % dicklyon@534: % Unless required by applicable law or agreed to in writing, software dicklyon@534: % distributed under the License is distributed on an "AS IS" BASIS, dicklyon@534: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. dicklyon@534: % See the License for the specific language governing permissions and dicklyon@534: % limitations under the License. dicklyon@534: dicklyon@534: function [ihc_out, state] = CARFAC_IHC_Step(filters_out, coeffs, state); dicklyon@534: % function [ihc_out, state] = CARFAC_IHC_Step(filters_out, coeffs, state); dicklyon@534: % dicklyon@534: % One sample-time update of inner-hair-cell (IHC) model, including the dicklyon@534: % detection nonlinearity and one or two capacitor state variables. dicklyon@534: dicklyon@534: just_hwr = coeffs.just_hwr; dicklyon@534: dicklyon@534: if just_hwr dicklyon@534: ihc_out = max(0, filters_out); dicklyon@534: state.ihc_accum = state.ihc_accum + ihc_out; dicklyon@534: else dicklyon@534: one_cap = coeffs.one_cap; dicklyon@534: dicklyon@534: detect = CARFAC_Detect(filters_out); % detect with HWR or so dicklyon@534: dicklyon@534: if one_cap dicklyon@534: ihc_out = detect .* state.cap_voltage; dicklyon@534: state.cap_voltage = state.cap_voltage - ihc_out .* coeffs.out_rate + ... dicklyon@534: (1 - state.cap_voltage) .* coeffs.in_rate; dicklyon@534: else dicklyon@534: % change to 2-cap version more like Meddis's: dicklyon@534: ihc_out = detect .* state.cap2_voltage; dicklyon@534: state.cap1_voltage = state.cap1_voltage - ... dicklyon@534: (state.cap1_voltage - state.cap2_voltage) .* coeffs.out1_rate + ... dicklyon@534: (1 - state.cap1_voltage) .* coeffs.in1_rate; dicklyon@534: dicklyon@534: state.cap2_voltage = state.cap2_voltage - ihc_out .* coeffs.out2_rate + ... dicklyon@534: (state.cap1_voltage - state.cap2_voltage) .* coeffs.in2_rate; dicklyon@534: end dicklyon@534: dicklyon@534: % smooth it twice with LPF: dicklyon@534: dicklyon@534: state.lpf1_state = state.lpf1_state + coeffs.lpf_coeff * ... dicklyon@534: (ihc_out - state.lpf1_state); dicklyon@534: dicklyon@534: state.lpf2_state = state.lpf2_state + coeffs.lpf_coeff * ... dicklyon@534: (state.lpf1_state - state.lpf2_state); dicklyon@534: dicklyon@534: ihc_out = state.lpf2_state - coeffs.rest_output; dicklyon@534: dicklyon@534: state.ihc_accum = state.ihc_accum + max(0, ihc_out); dicklyon@534: end