ronw@700: % Copyright 2013, Google, Inc. ronw@700: % Author: Richard F. Lyon ronw@700: % ronw@700: % This Matlab file is part of an implementation of Lyon's cochlear model: ronw@700: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" ronw@700: % to supplement Lyon's upcoming book "Human and Machine Hearing" ronw@700: % ronw@700: % Licensed under the Apache License, Version 2.0 (the "License"); ronw@700: % you may not use this file except in compliance with the License. ronw@700: % You may obtain a copy of the License at ronw@700: % ronw@700: % http://www.apache.org/licenses/LICENSE-2.0 ronw@700: % ronw@700: % Unless required by applicable law or agreed to in writing, software ronw@700: % distributed under the License is distributed on an "AS IS" BASIS, ronw@700: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ronw@700: % See the License for the specific language governing permissions and ronw@700: % limitations under the License. ronw@700: ronw@700: function sai_struct = SAI_Run_Segment(sai_struct, input) ronw@700: % function sai_frame = SAI_Run_Segment(sai_struct, input) ronw@700: % Compute a single SAI frame from the given multichannel input signal. ronw@700: ronw@700: % Store state used between successive calls to this function in sai_struct. ronw@700: if ~isfield(sai_struct, 'nap_buffer') ronw@700: % Make the history buffer. ronw@700: buffer_width = sai_struct.width + ... ronw@700: floor((1 + (sai_struct.n_window_pos - 1)/2) * sai_struct.window_width); ronw@700: n_ch = size(input, 2); ronw@700: sai_struct.nap_buffer = zeros(buffer_width, n_ch); ronw@700: end ronw@700: if ~isfield(sai_struct, 'frame') ronw@700: % The SAI frame is transposed to be image-like. ronw@700: sai_struct.frame = zeros(n_ch, sai_struct.width); ronw@700: end ronw@700: ronw@700: if size(input, 1) < sai_struct.window_width % pad out the last result ronw@700: input = [input; ... ronw@700: zeros(sai_struct.window_width - size(input, 1), size(input, 2))]; ronw@700: end ronw@700: size(input) ronw@700: sai_struct.window_width ronw@700: ronw@700: assert(size(input, 1) == sai_struct.window_width) ronw@700: ronw@700: % Shift new data into the buffer. ronw@700: num_shift = size(input, 1); ronw@700: sai_struct.nap_buffer = [sai_struct.nap_buffer((1 + num_shift):end,:); ... ronw@700: input]; ronw@700: ronw@700: sai_struct = SAI_StabilizeLayer(sai_struct); ronw@700: ronw@700: return