annotate matlab/bmm/carfac/CARFAC_IHCStep.m @ 462:87699cb4cf71

Major AGC improvements mostly
author dicklyon@google.com
date Thu, 01 Mar 2012 19:49:24 +0000
parents f8ba7ad93fa9
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
tom@455 20 function [ihc_out, state] = CARFAC_IHCStep(filters_out, coeffs, state);
tom@455 21 % function [ihc_out, state] = CARFAC_IHCStep(filters_out, coeffs, state);
tom@455 22 %
tom@455 23 % One sample-time update of inner-hair-cell (IHC) model, including the
tom@455 24 % detection nonlinearity and one or two capacitor state variables.
tom@455 25
tom@455 26 just_hwr = coeffs.just_hwr;
tom@455 27
tom@455 28 if just_hwr
tom@455 29 ihc_out = max(0, filters_out);
dicklyon@462 30 state.ihc_accum = state.ihc_accum + ihc_out;
tom@455 31 else
tom@455 32 one_cap = coeffs.one_cap;
tom@455 33
dicklyon@462 34 detect = CARFAC_Detect(filters_out); % detect with HWR or so
tom@455 35
tom@455 36 if one_cap
tom@455 37 ihc_out = detect .* state.cap_voltage;
tom@455 38 state.cap_voltage = state.cap_voltage - ihc_out .* coeffs.out_rate + ...
tom@455 39 (1 - state.cap_voltage) .* coeffs.in_rate;
tom@455 40 else
tom@455 41 % change to 2-cap version more like Meddis's:
tom@455 42 ihc_out = detect .* state.cap2_voltage;
tom@455 43 state.cap1_voltage = state.cap1_voltage - ...
tom@455 44 (state.cap1_voltage - state.cap2_voltage) .* coeffs.out1_rate + ...
tom@455 45 (1 - state.cap1_voltage) .* coeffs.in1_rate;
tom@455 46
tom@455 47 state.cap2_voltage = state.cap2_voltage - ihc_out .* coeffs.out2_rate + ...
tom@455 48 (state.cap1_voltage - state.cap2_voltage) .* coeffs.in2_rate;
tom@455 49 end
tom@455 50
tom@455 51 % smooth it twice with LPF:
tom@455 52
tom@455 53 state.lpf1_state = state.lpf1_state + coeffs.lpf_coeff * ...
tom@455 54 (ihc_out - state.lpf1_state);
tom@455 55
tom@455 56 state.lpf2_state = state.lpf2_state + coeffs.lpf_coeff * ...
tom@455 57 (state.lpf1_state - state.lpf2_state);
tom@455 58
dicklyon@462 59 ihc_out = state.lpf2_state - coeffs.rest_output;
tom@455 60
dicklyon@462 61 state.ihc_accum = state.ihc_accum + max(0, ihc_out);
tom@455 62 end