annotate trunk/matlab/bmm/carfac/CARFAC_Spatial_Smooth.m @ 527:bef16790194e

added some missing headers
author dicklyon@google.com
date Wed, 07 Mar 2012 23:18:32 +0000
parents 2b96cb7ea4f7
children 95a11cca4619
rev   line source
dicklyon@527 1 % Copyright 2012, Google, Inc.
dicklyon@527 2 % Author: Richard F. Lyon
dicklyon@527 3 %
dicklyon@527 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@527 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@527 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@527 7 %
dicklyon@527 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@527 9 % you may not use this file except in compliance with the License.
dicklyon@527 10 % You may obtain a copy of the License at
dicklyon@527 11 %
dicklyon@527 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@527 13 %
dicklyon@527 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@527 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@527 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@527 17 % See the License for the specific language governing permissions and
dicklyon@527 18 % limitations under the License.
dicklyon@527 19
dicklyon@523 20 function stage_state = CARFAC_Spatial_Smooth(coeffs, stage, stage_state)
dicklyon@523 21 % function AGC_state = CARFAC_Spatial_Smooth( ...
dicklyon@523 22 % n_taps, n_iterations, FIR_coeffs, AGC_state)
dicklyon@523 23
dicklyon@523 24 n_iterations = coeffs.AGC_spatial_iterations(stage);
dicklyon@523 25
dicklyon@523 26 use_FIR = n_iterations < 4; % or whatever condition we want to try
dicklyon@523 27
dicklyon@523 28 if use_FIR
dicklyon@523 29 FIR_coeffs = coeffs.AGC_spatial_FIR(:,stage);
dicklyon@523 30 switch coeffs.AGC_n_taps(stage)
dicklyon@523 31 case 3
dicklyon@523 32 for iter = 1:n_iterations
dicklyon@523 33 stage_state = ...
dicklyon@523 34 FIR_coeffs(1) * stage_state([1, 1:(end-1)], :) + ...
dicklyon@523 35 FIR_coeffs(2) * stage_state + ...
dicklyon@523 36 FIR_coeffs(3) * stage_state([2:end, end], :);
dicklyon@523 37 end
dicklyon@523 38 case 5 % 5-tap smoother duplicates first and last coeffs:
dicklyon@523 39 for iter = 1:n_iterations
dicklyon@523 40 stage_state = ...
dicklyon@523 41 FIR_coeffs(1) * (stage_state([1, 1, 1:(end-2)], :) + ...
dicklyon@523 42 stage_state([1, 1:(end-1)], :)) + ...
dicklyon@523 43 FIR_coeffs(2) * stage_state + ...
dicklyon@523 44 FIR_coeffs(3) * (stage_state([2:end, end], :) + ...
dicklyon@523 45 stage_state([3:end, end, end], :));
dicklyon@523 46 end
dicklyon@523 47 otherwise
dicklyon@523 48 error('Bad n_taps in CARFAC_Spatial_Smooth');
dicklyon@523 49 end
dicklyon@523 50 else
dicklyon@523 51 % use IIR method, back-and-forth firt-order smoothers:
dicklyon@523 52 stage_state = SmoothDoubleExponential(stage_state, ...
dicklyon@523 53 coeffs.AGC_polez1(stage), coeffs.AGC_polez2(stage));
dicklyon@523 54 end