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