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