annotate trunk/matlab/bmm/carfac/SAI_BlendFrameIntoComposite.m @ 703:2bd09040ecf0

Better SAI unit tests. Includes a test to compare the output of the Matlab and C++ version which is currently disabled since the outputs are not identical.
author ronw@google.com
date Mon, 01 Jul 2013 19:02:37 +0000
parents d0ff15c36828
children
rev   line source
dicklyon@615 1 % Copyright 2013, Google, Inc.
dicklyon@615 2 % Author: Richard F. Lyon
dicklyon@615 3 %
dicklyon@615 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@615 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@615 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@615 7 %
dicklyon@615 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@615 9 % you may not use this file except in compliance with the License.
dicklyon@615 10 % You may obtain a copy of the License at
dicklyon@615 11 %
dicklyon@615 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@615 13 %
dicklyon@615 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@615 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@615 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@615 17 % See the License for the specific language governing permissions and
dicklyon@615 18 % limitations under the License.
dicklyon@615 19
dicklyon@619 20 function composite_frame = SAI_BlendFrameIntoComposite( ...
dicklyon@615 21 layer_struct, composite_frame)
dicklyon@615 22
dicklyon@619 23 new_frame = layer_struct.frame;
dicklyon@665 24 n_ch = size(new_frame, 1);
dicklyon@665 25
dicklyon@665 26 if layer_struct.right_overlap == 0 % A layer 1 hack only.
dicklyon@665 27 for row = 1:n_ch
dicklyon@665 28 % Taper new_frame down near zero lag for a nicer result...
dicklyon@665 29 taper_size = round(6 + 60*(row/n_ch)^2); % hack
dicklyon@665 30 zero_pos = layer_struct.frame_width - layer_struct.future_lags;
dicklyon@665 31 taper = [-taper_size:min(taper_size, layer_struct.future_lags)];
dicklyon@665 32 col_range = zero_pos + taper;
dicklyon@665 33 taper = (0.4 + 0.6*abs(taper) / taper_size) .^ 2;
dicklyon@665 34 taper(taper == 0) = 0.5;
dicklyon@665 35 new_frame(row, col_range) = new_frame(row, col_range) .* taper;
dicklyon@665 36 end
dicklyon@665 37 end
dicklyon@665 38
dicklyon@615 39 alpha = layer_struct.alpha;
dicklyon@615 40 lag_curve = layer_struct.lag_curve;
dicklyon@615 41 target_columns = layer_struct.target_indices;
dicklyon@615 42
dicklyon@615 43 frame_width = size(new_frame, 2);
dicklyon@615 44
dicklyon@615 45 % Lags are measured from 0 at the right.
dicklyon@615 46 stretched_frame = interp1(new_frame', frame_width - lag_curve)';
dicklyon@615 47 alpha = repmat(alpha, size(new_frame, 1), 1);
dicklyon@615 48 composite_frame(:, target_columns) = ...
dicklyon@615 49 (1 - alpha) .* composite_frame(:, target_columns) + ...
dicklyon@615 50 alpha .* stretched_frame;