annotate trunk/matlab/bmm/carfac/CARFAC_IHCStep.m @ 518:62c2f21d7a75

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