ronw@700
|
1 % Copyright 2013, Google, Inc.
|
ronw@700
|
2 % Author: Richard F. Lyon
|
ronw@700
|
3 %
|
ronw@700
|
4 % This Matlab file is part of an implementation of Lyon's cochlear model:
|
ronw@700
|
5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
|
ronw@700
|
6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
|
ronw@700
|
7 %
|
ronw@700
|
8 % Licensed under the Apache License, Version 2.0 (the "License");
|
ronw@700
|
9 % you may not use this file except in compliance with the License.
|
ronw@700
|
10 % You may obtain a copy of the License at
|
ronw@700
|
11 %
|
ronw@700
|
12 % http://www.apache.org/licenses/LICENSE-2.0
|
ronw@700
|
13 %
|
ronw@700
|
14 % Unless required by applicable law or agreed to in writing, software
|
ronw@700
|
15 % distributed under the License is distributed on an "AS IS" BASIS,
|
ronw@700
|
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
ronw@700
|
17 % See the License for the specific language governing permissions and
|
ronw@700
|
18 % limitations under the License.
|
ronw@700
|
19
|
ronw@700
|
20 function sai_struct = SAI_Run_Segment(sai_struct, input)
|
ronw@700
|
21 % function sai_frame = SAI_Run_Segment(sai_struct, input)
|
ronw@700
|
22 % Compute a single SAI frame from the given multichannel input signal.
|
ronw@700
|
23
|
ronw@700
|
24 % Store state used between successive calls to this function in sai_struct.
|
ronw@700
|
25 if ~isfield(sai_struct, 'nap_buffer')
|
ronw@700
|
26 % Make the history buffer.
|
ronw@700
|
27 buffer_width = sai_struct.width + ...
|
ronw@700
|
28 floor((1 + (sai_struct.n_window_pos - 1)/2) * sai_struct.window_width);
|
ronw@700
|
29 n_ch = size(input, 2);
|
ronw@700
|
30 sai_struct.nap_buffer = zeros(buffer_width, n_ch);
|
ronw@700
|
31 end
|
ronw@700
|
32 if ~isfield(sai_struct, 'frame')
|
ronw@700
|
33 % The SAI frame is transposed to be image-like.
|
ronw@700
|
34 sai_struct.frame = zeros(n_ch, sai_struct.width);
|
ronw@700
|
35 end
|
ronw@700
|
36
|
ronw@700
|
37 if size(input, 1) < sai_struct.window_width % pad out the last result
|
ronw@700
|
38 input = [input; ...
|
ronw@700
|
39 zeros(sai_struct.window_width - size(input, 1), size(input, 2))];
|
ronw@700
|
40 end
|
ronw@700
|
41 size(input)
|
ronw@700
|
42 sai_struct.window_width
|
ronw@700
|
43
|
ronw@700
|
44 assert(size(input, 1) == sai_struct.window_width)
|
ronw@700
|
45
|
ronw@700
|
46 % Shift new data into the buffer.
|
ronw@700
|
47 num_shift = size(input, 1);
|
ronw@700
|
48 sai_struct.nap_buffer = [sai_struct.nap_buffer((1 + num_shift):end,:); ...
|
ronw@700
|
49 input];
|
ronw@700
|
50
|
ronw@700
|
51 sai_struct = SAI_StabilizeLayer(sai_struct);
|
ronw@700
|
52
|
ronw@700
|
53 return
|