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