Mercurial > hg > aimc
diff trunk/matlab/bmm/carfac/SAI_Run_Segment.m @ 700:597913e855fd
Factor out SAI_Run_Segment, and output test_data for comparison with C++ code.
author | ronw@google.com |
---|---|
date | Thu, 27 Jun 2013 22:28:42 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/matlab/bmm/carfac/SAI_Run_Segment.m Thu Jun 27 22:28:42 2013 +0000 @@ -0,0 +1,53 @@ +% Copyright 2013, Google, Inc. +% Author: Richard F. Lyon +% +% This Matlab file is part of an implementation of Lyon's cochlear model: +% "Cascade of Asymmetric Resonators with Fast-Acting Compression" +% to supplement Lyon's upcoming book "Human and Machine Hearing" +% +% Licensed under the Apache License, Version 2.0 (the "License"); +% you may not use this file except in compliance with the License. +% You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +% See the License for the specific language governing permissions and +% limitations under the License. + +function sai_struct = SAI_Run_Segment(sai_struct, input) +% function sai_frame = SAI_Run_Segment(sai_struct, input) +% Compute a single SAI frame from the given multichannel input signal. + +% Store state used between successive calls to this function in sai_struct. +if ~isfield(sai_struct, 'nap_buffer') + % Make the history buffer. + buffer_width = sai_struct.width + ... + floor((1 + (sai_struct.n_window_pos - 1)/2) * sai_struct.window_width); + n_ch = size(input, 2); + sai_struct.nap_buffer = zeros(buffer_width, n_ch); +end +if ~isfield(sai_struct, 'frame') + % The SAI frame is transposed to be image-like. + sai_struct.frame = zeros(n_ch, sai_struct.width); +end + +if size(input, 1) < sai_struct.window_width % pad out the last result + input = [input; ... + zeros(sai_struct.window_width - size(input, 1), size(input, 2))]; +end +size(input) +sai_struct.window_width + +assert(size(input, 1) == sai_struct.window_width) + +% Shift new data into the buffer. +num_shift = size(input, 1); +sai_struct.nap_buffer = [sai_struct.nap_buffer((1 + num_shift):end,:); ... + input]; + +sai_struct = SAI_StabilizeLayer(sai_struct); + +return