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
|
dicklyon@561
|
20 function CF = CARFAC_Init(CF)
|
dicklyon@561
|
21 % function CF = CARFAC_Init(CF)
|
tom@516
|
22 %
|
dicklyon@561
|
23 % Initialize state for one or more ears of CF.
|
dicklyon@561
|
24 % This allocates and zeros all the state vector storage in the CF struct.
|
tom@516
|
25
|
dicklyon@561
|
26 n_ears = CF.n_ears;
|
tom@516
|
27
|
dicklyon@534
|
28 for ear = 1:n_ears
|
dicklyon@534
|
29 % for now there's only one coeffs, not one per ear
|
dicklyon@561
|
30 CF.ears(ear).CAR_state = CAR_Init_State(CF.ears(ear).CAR_coeffs);
|
dicklyon@561
|
31 CF.ears(ear).IHC_state = IHC_Init_State(CF.ears(ear).IHC_coeffs);
|
dicklyon@561
|
32 CF.ears(ear).AGC_state = AGC_Init_State(CF.ears(ear).AGC_coeffs);
|
dicklyon@534
|
33 end
|
dicklyon@523
|
34
|
dicklyon@534
|
35
|
dicklyon@534
|
36 function state = CAR_Init_State(coeffs)
|
dicklyon@534
|
37 n_ch = coeffs.n_ch;
|
dicklyon@534
|
38 state = struct( ...
|
dicklyon@534
|
39 'z1_memory', zeros(n_ch, 1), ...
|
dicklyon@534
|
40 'z2_memory', zeros(n_ch, 1), ...
|
dicklyon@534
|
41 'zA_memory', zeros(n_ch, 1), ...
|
dicklyon@617
|
42 'zB_memory', coeffs.zr_coeffs, ...
|
dicklyon@534
|
43 'dzB_memory', zeros(n_ch, 1), ...
|
dicklyon@534
|
44 'zY_memory', zeros(n_ch, 1), ...
|
dicklyon@534
|
45 'g_memory', coeffs.g0_coeffs, ...
|
dicklyon@534
|
46 'dg_memory', zeros(n_ch, 1) ...
|
dicklyon@534
|
47 );
|
dicklyon@534
|
48
|
dicklyon@534
|
49
|
dicklyon@534
|
50 function state = AGC_Init_State(coeffs)
|
dicklyon@665
|
51 n_ch = coeffs(1).n_ch;
|
dicklyon@665
|
52 n_AGC_stages = coeffs(1).n_AGC_stages;
|
dicklyon@665
|
53 state = struct([]);
|
dicklyon@665
|
54 for stage = 1:n_AGC_stages
|
dicklyon@665
|
55 % Initialize state recursively...
|
dicklyon@665
|
56 state(stage).AGC_memory = zeros(n_ch, 1);
|
dicklyon@665
|
57 state(stage).input_accum = zeros(n_ch, 1);
|
dicklyon@665
|
58 state(stage).decim_phase = 0; % integer decimator phase
|
dicklyon@665
|
59 end
|
dicklyon@534
|
60
|
dicklyon@534
|
61
|
dicklyon@534
|
62 function state = IHC_Init_State(coeffs)
|
dicklyon@534
|
63 n_ch = coeffs.n_ch;
|
dicklyon@556
|
64 if coeffs.just_hwr
|
dicklyon@556
|
65 state = struct('ihc_accum', zeros(n_ch, 1));
|
dicklyon@556
|
66 else
|
dicklyon@556
|
67 if coeffs.one_cap
|
dicklyon@556
|
68 state = struct( ...
|
dicklyon@556
|
69 'ihc_accum', zeros(n_ch, 1), ...
|
dicklyon@556
|
70 'cap_voltage', coeffs.rest_cap * ones(n_ch, 1), ...
|
dicklyon@556
|
71 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ...
|
dicklyon@565
|
72 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ...
|
dicklyon@565
|
73 'ac_coupler', zeros(n_ch, 1) ...
|
dicklyon@556
|
74 );
|
dicklyon@556
|
75 else
|
dicklyon@556
|
76 state = struct( ...
|
dicklyon@556
|
77 'ihc_accum', zeros(n_ch, 1), ...
|
dicklyon@556
|
78 'cap1_voltage', coeffs.rest_cap1 * ones(n_ch, 1), ...
|
dicklyon@556
|
79 'cap2_voltage', coeffs.rest_cap2* ones(n_ch, 1), ...
|
dicklyon@556
|
80 'lpf1_state', coeffs.rest_output * ones(n_ch, 1), ...
|
dicklyon@565
|
81 'lpf2_state', coeffs.rest_output * ones(n_ch, 1), ...
|
dicklyon@565
|
82 'ac_coupler', zeros(n_ch, 1) ...
|
dicklyon@556
|
83 );
|
dicklyon@556
|
84 end
|
dicklyon@556
|
85 end
|
dicklyon@534
|
86
|
dicklyon@556
|
87
|
dicklyon@556
|
88
|