tom@455
|
1 % Copyright 2012, Google, Inc.
|
tom@455
|
2 % Author: Richard F. Lyon
|
tom@455
|
3 %
|
tom@455
|
4 % This Matlab file is part of an implementation of Lyon's cochlear model:
|
tom@455
|
5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
|
tom@455
|
6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
|
tom@455
|
7 %
|
tom@455
|
8 % Licensed under the Apache License, Version 2.0 (the "License");
|
tom@455
|
9 % you may not use this file except in compliance with the License.
|
tom@455
|
10 % You may obtain a copy of the License at
|
tom@455
|
11 %
|
tom@455
|
12 % http://www.apache.org/licenses/LICENSE-2.0
|
tom@455
|
13 %
|
tom@455
|
14 % Unless required by applicable law or agreed to in writing, software
|
tom@455
|
15 % distributed under the License is distributed on an "AS IS" BASIS,
|
tom@455
|
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tom@455
|
17 % See the License for the specific language governing permissions and
|
tom@455
|
18 % limitations under the License.
|
tom@455
|
19
|
tom@455
|
20 function [CF, sai] = CARFAC_SAI(CF, k, n_mics, naps, sai)
|
tom@455
|
21 % function sai = CARFAC_SAI(CF_struct, n_mics, naps, sai)
|
tom@455
|
22 %
|
tom@455
|
23 % Calculate the Stabilized Auditory Image from naps
|
tom@455
|
24 %
|
tom@455
|
25
|
tom@455
|
26 threshold_alpha = CF.sai_params.threshold_alpha;
|
tom@455
|
27 threshold_jump = CF.sai_params.threshold_jump_factor;
|
tom@455
|
28 threshold_offset = CF.sai_params.threshold_jump_offset;
|
tom@455
|
29
|
tom@455
|
30 sai2 = reshape(sai,CF.sai_params.sai_width * CF.n_ch,n_mics);
|
tom@455
|
31 naps2 = reshape(naps,CF.n_samp * CF.n_ch,n_mics);
|
tom@455
|
32
|
tom@455
|
33 for mic = 1:n_mics
|
tom@455
|
34 data = naps(k, :, mic)';
|
tom@455
|
35 above_threshold = (CF.sai_state(mic).lastdata > ...
|
tom@455
|
36 CF.sai_state(mic).thresholds) & ...
|
tom@455
|
37 (CF.sai_state(mic).lastdata > data);
|
tom@455
|
38 CF.sai_state(mic).thresholds(above_threshold) = ...
|
tom@455
|
39 data(above_threshold) * threshold_jump + threshold_offset;
|
tom@455
|
40 CF.sai_state(mic).thresholds(~above_threshold) = ...
|
tom@455
|
41 CF.sai_state(mic).thresholds(~above_threshold) * threshold_alpha;
|
tom@455
|
42 CF.sai_state(mic).lastdata = data;
|
tom@455
|
43
|
tom@455
|
44 % Update SAI image with strobe data.
|
tom@455
|
45 othermic = 3 - mic;
|
tom@455
|
46
|
tom@455
|
47 % Channels that are above the threhsold
|
tom@455
|
48 above_ch = find(above_threshold);
|
tom@455
|
49
|
tom@455
|
50 % If we are above the threshold, set the trigger index and reset the
|
tom@455
|
51 % sai_index
|
tom@455
|
52 CF.sai_state(mic).trigger_index(above_ch) = k;
|
tom@455
|
53 CF.sai_state(mic).sai_index(above_ch) = 1;
|
tom@455
|
54
|
tom@455
|
55 % Copy the right data from the nap to the sai
|
tom@455
|
56 chans = (1:CF.n_ch)';
|
tom@455
|
57 fromindices = CF.sai_state(mic).trigger_index() + (chans - 1) * CF.n_samp;
|
tom@455
|
58 toindices = min((CF.sai_state(mic).sai_index() + (chans - 1) * ...
|
tom@455
|
59 CF.sai_params.sai_width), ...
|
tom@455
|
60 CF.sai_params.sai_width * CF.n_ch);
|
tom@455
|
61 sai2(toindices,mic) = naps2(fromindices,othermic);
|
tom@455
|
62
|
tom@455
|
63 CF.sai_state(mic).trigger_index(:) = CF.sai_state(mic).trigger_index(:) + 1;
|
tom@455
|
64 CF.sai_state(mic).sai_index(:) = CF.sai_state(mic).sai_index(:) + 1;
|
tom@455
|
65
|
tom@455
|
66 end
|
tom@455
|
67
|
tom@455
|
68 sai = reshape(sai2,CF.sai_params.sai_width,CF.n_ch,n_mics);
|
tom@455
|
69 naps = reshape(naps2,CF.n_samp, CF.n_ch,n_mics);
|
tom@455
|
70
|