dicklyon@527
|
1 % Copyright 2012, Google, Inc.
|
dicklyon@527
|
2 % Author: Richard F. Lyon
|
dicklyon@527
|
3 %
|
dicklyon@527
|
4 % This Matlab file is part of an implementation of Lyon's cochlear model:
|
dicklyon@527
|
5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
|
dicklyon@527
|
6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
|
dicklyon@527
|
7 %
|
dicklyon@527
|
8 % Licensed under the Apache License, Version 2.0 (the "License");
|
dicklyon@527
|
9 % you may not use this file except in compliance with the License.
|
dicklyon@527
|
10 % You may obtain a copy of the License at
|
dicklyon@527
|
11 %
|
dicklyon@527
|
12 % http://www.apache.org/licenses/LICENSE-2.0
|
dicklyon@527
|
13 %
|
dicklyon@527
|
14 % Unless required by applicable law or agreed to in writing, software
|
dicklyon@527
|
15 % distributed under the License is distributed on an "AS IS" BASIS,
|
dicklyon@527
|
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
dicklyon@527
|
17 % See the License for the specific language governing permissions and
|
dicklyon@527
|
18 % limitations under the License.
|
dicklyon@527
|
19
|
dicklyon@665
|
20 function stage_state = CARFAC_Spatial_Smooth(coeffs, stage_state)
|
dicklyon@523
|
21 % function AGC_state = CARFAC_Spatial_Smooth( ...
|
dicklyon@523
|
22 % n_taps, n_iterations, FIR_coeffs, AGC_state)
|
dicklyon@523
|
23
|
dicklyon@665
|
24 n_iterations = coeffs.AGC_spatial_iterations;
|
dicklyon@523
|
25
|
dicklyon@523
|
26 use_FIR = n_iterations < 4; % or whatever condition we want to try
|
dicklyon@523
|
27
|
dicklyon@523
|
28 if use_FIR
|
dicklyon@665
|
29 FIR_coeffs = coeffs.AGC_spatial_FIR;
|
dicklyon@665
|
30 switch coeffs.AGC_spatial_n_taps
|
dicklyon@523
|
31 case 3
|
dicklyon@523
|
32 for iter = 1:n_iterations
|
dicklyon@523
|
33 stage_state = ...
|
dicklyon@523
|
34 FIR_coeffs(1) * stage_state([1, 1:(end-1)], :) + ...
|
dicklyon@523
|
35 FIR_coeffs(2) * stage_state + ...
|
dicklyon@523
|
36 FIR_coeffs(3) * stage_state([2:end, end], :);
|
dicklyon@523
|
37 end
|
dicklyon@523
|
38 case 5 % 5-tap smoother duplicates first and last coeffs:
|
dicklyon@523
|
39 for iter = 1:n_iterations
|
dicklyon@523
|
40 stage_state = ...
|
dicklyon@534
|
41 FIR_coeffs(1) * (stage_state([1, 2, 1:(end-2)], :) + ...
|
dicklyon@523
|
42 stage_state([1, 1:(end-1)], :)) + ...
|
dicklyon@523
|
43 FIR_coeffs(2) * stage_state + ...
|
dicklyon@523
|
44 FIR_coeffs(3) * (stage_state([2:end, end], :) + ...
|
dicklyon@534
|
45 stage_state([3:end, end, end-1], :));
|
dicklyon@523
|
46 end
|
dicklyon@523
|
47 otherwise
|
dicklyon@536
|
48 error('Bad AGC_spatial_n_taps in CARFAC_Spatial_Smooth');
|
dicklyon@523
|
49 end
|
dicklyon@523
|
50 else
|
dicklyon@536
|
51 % use IIR method, back-and-forth first-order smoothers:
|
dicklyon@523
|
52 stage_state = SmoothDoubleExponential(stage_state, ...
|
dicklyon@523
|
53 coeffs.AGC_polez1(stage), coeffs.AGC_polez2(stage));
|
dicklyon@523
|
54 end
|