annotate matlab/bmm/carfac/SAI_BlendFrameIntoComposite.m @ 646:e76951e4da20

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