dicklyon@466: % Copyright 2012, Google, Inc. dicklyon@466: % Author: Richard F. Lyon dicklyon@466: % dicklyon@466: % This Matlab file is part of an implementation of Lyon's cochlear model: dicklyon@466: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" dicklyon@466: % to supplement Lyon's upcoming book "Human and Machine Hearing" dicklyon@466: % dicklyon@466: % Licensed under the Apache License, Version 2.0 (the "License"); dicklyon@466: % you may not use this file except in compliance with the License. dicklyon@466: % You may obtain a copy of the License at dicklyon@466: % dicklyon@466: % http://www.apache.org/licenses/LICENSE-2.0 dicklyon@466: % dicklyon@466: % Unless required by applicable law or agreed to in writing, software dicklyon@466: % distributed under the License is distributed on an "AS IS" BASIS, dicklyon@466: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. dicklyon@466: % See the License for the specific language governing permissions and dicklyon@466: % limitations under the License. dicklyon@466: dicklyon@462: function stage_state = CARFAC_Spatial_Smooth(coeffs, stage, stage_state) dicklyon@462: % function AGC_state = CARFAC_Spatial_Smooth( ... dicklyon@462: % n_taps, n_iterations, FIR_coeffs, AGC_state) dicklyon@462: dicklyon@462: n_iterations = coeffs.AGC_spatial_iterations(stage); dicklyon@462: dicklyon@462: use_FIR = n_iterations < 4; % or whatever condition we want to try dicklyon@462: dicklyon@462: if use_FIR dicklyon@462: FIR_coeffs = coeffs.AGC_spatial_FIR(:,stage); dicklyon@462: switch coeffs.AGC_n_taps(stage) dicklyon@462: case 3 dicklyon@462: for iter = 1:n_iterations dicklyon@462: stage_state = ... dicklyon@462: FIR_coeffs(1) * stage_state([1, 1:(end-1)], :) + ... dicklyon@462: FIR_coeffs(2) * stage_state + ... dicklyon@462: FIR_coeffs(3) * stage_state([2:end, end], :); dicklyon@462: end dicklyon@462: case 5 % 5-tap smoother duplicates first and last coeffs: dicklyon@462: for iter = 1:n_iterations dicklyon@462: stage_state = ... dicklyon@473: FIR_coeffs(1) * (stage_state([1, 2, 1:(end-2)], :) + ... dicklyon@462: stage_state([1, 1:(end-1)], :)) + ... dicklyon@462: FIR_coeffs(2) * stage_state + ... dicklyon@462: FIR_coeffs(3) * (stage_state([2:end, end], :) + ... dicklyon@473: stage_state([3:end, end, end-1], :)); dicklyon@462: end dicklyon@462: otherwise dicklyon@462: error('Bad n_taps in CARFAC_Spatial_Smooth'); dicklyon@462: end dicklyon@462: else dicklyon@462: % use IIR method, back-and-forth firt-order smoothers: dicklyon@462: stage_state = SmoothDoubleExponential(stage_state, ... dicklyon@462: coeffs.AGC_polez1(stage), coeffs.AGC_polez2(stage)); dicklyon@462: end