annotate matlab/bmm/carfac/CARFAC_IHC_Step.m @ 473:b4da807f4318

Add CARFAC_Design_Doc.txt, CARFAC_Run_Segment.m, and some renames; rename various variables to be more parallel; clean up init code and such.
author dicklyon@google.com
date Fri, 16 Mar 2012 04:19:24 +0000
parents
children 69955736f586
rev   line source
dicklyon@473 1 % Copyright 2012, Google, Inc.
dicklyon@473 2 % Author: Richard F. Lyon
dicklyon@473 3 %
dicklyon@473 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@473 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@473 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@473 7 %
dicklyon@473 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@473 9 % you may not use this file except in compliance with the License.
dicklyon@473 10 % You may obtain a copy of the License at
dicklyon@473 11 %
dicklyon@473 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@473 13 %
dicklyon@473 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@473 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@473 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@473 17 % See the License for the specific language governing permissions and
dicklyon@473 18 % limitations under the License.
dicklyon@473 19
dicklyon@473 20 function [ihc_out, state] = CARFAC_IHC_Step(filters_out, coeffs, state);
dicklyon@473 21 % function [ihc_out, state] = CARFAC_IHC_Step(filters_out, coeffs, state);
dicklyon@473 22 %
dicklyon@473 23 % One sample-time update of inner-hair-cell (IHC) model, including the
dicklyon@473 24 % detection nonlinearity and one or two capacitor state variables.
dicklyon@473 25
dicklyon@473 26 just_hwr = coeffs.just_hwr;
dicklyon@473 27
dicklyon@473 28 if just_hwr
dicklyon@473 29 ihc_out = max(0, filters_out);
dicklyon@473 30 state.ihc_accum = state.ihc_accum + ihc_out;
dicklyon@473 31 else
dicklyon@473 32 one_cap = coeffs.one_cap;
dicklyon@473 33
dicklyon@473 34 detect = CARFAC_Detect(filters_out); % detect with HWR or so
dicklyon@473 35
dicklyon@473 36 if one_cap
dicklyon@473 37 ihc_out = detect .* state.cap_voltage;
dicklyon@473 38 state.cap_voltage = state.cap_voltage - ihc_out .* coeffs.out_rate + ...
dicklyon@473 39 (1 - state.cap_voltage) .* coeffs.in_rate;
dicklyon@473 40 else
dicklyon@473 41 % change to 2-cap version more like Meddis's:
dicklyon@473 42 ihc_out = detect .* state.cap2_voltage;
dicklyon@473 43 state.cap1_voltage = state.cap1_voltage - ...
dicklyon@473 44 (state.cap1_voltage - state.cap2_voltage) .* coeffs.out1_rate + ...
dicklyon@473 45 (1 - state.cap1_voltage) .* coeffs.in1_rate;
dicklyon@473 46
dicklyon@473 47 state.cap2_voltage = state.cap2_voltage - ihc_out .* coeffs.out2_rate + ...
dicklyon@473 48 (state.cap1_voltage - state.cap2_voltage) .* coeffs.in2_rate;
dicklyon@473 49 end
dicklyon@473 50
dicklyon@473 51 % smooth it twice with LPF:
dicklyon@473 52
dicklyon@473 53 state.lpf1_state = state.lpf1_state + coeffs.lpf_coeff * ...
dicklyon@473 54 (ihc_out - state.lpf1_state);
dicklyon@473 55
dicklyon@473 56 state.lpf2_state = state.lpf2_state + coeffs.lpf_coeff * ...
dicklyon@473 57 (state.lpf1_state - state.lpf2_state);
dicklyon@473 58
dicklyon@473 59 ihc_out = state.lpf2_state - coeffs.rest_output;
dicklyon@473 60
dicklyon@473 61 state.ihc_accum = state.ihc_accum + max(0, ihc_out);
dicklyon@473 62 end