function stage_state = lyon2011_spatialsmooth(coeffs, stage_state)
%LYON2011_SPATIALSMOOTH spatial smoothing using FIR coefficients
%
% Usage: stage_state = lyon2011_spatialsmooth(coeffs, stage_state)
%
% Input parameters:
% coeffs : struct containing coeffs from AGC stage
% stage_state : smoothed coefficients
%
% Output parameters:
% stage_state : smoothed state array
%
% ´LYON2011_SPATIALSMOOTH´ performs spatial smoothing. This
% file is part of an implementation of Lyon's cochlear model:
% "Cascade of Asymmetric Resonators with Fast-Acting Compression"
%
%
% See also: lyon2011 demo_lyon2011
%
% References:
% R. F. Lyon. Cascades of two-pole–two-zero asymmetric resonators are
% good models of peripheral auditory function. J. Acoust. Soc. Am.,
% 130(6), 2011.
%
%
% Url: http://amtoolbox.org/amt-1.5.0/doc/modelstages/lyon2011_spatialsmooth.php
% #StatusDoc: Good
% #StatusCode: Good
% #Verification: Unknown
% #License: Apache2
% #Author: Richard F. Lyon (2013): original implementation (https://github.com/google/carfac)
% #Author: Amin Saremi (2016): adaptations for the AMT
% #Author: Clara Hollomey (2021): integration in the AMT 1.0
% #Author: Richard Lyon (2022): bug fixes for AMT
% #Author: Mihajlo Velimirovic (2022): implementation of the option ihc_potential
% This file is licensed unter the Apache License Version 2.0 which details can
% be found in the AMT directory "licences" and at
% <http://www.apache.org/licenses/LICENSE-2.0>.
% You must not use this file except in compliance with the Apache License
% Version 2.0. Unless required by applicable law or agreed to in writing, this
% file is distributed on an "as is" basis, without warranties or conditions
% of any kind, either express or implied.
% 1 iteration, 3-tap FIR.
% ignore n_iterations, implicitly 1; ignore AGC_spatial_n_taps, too.
FIR_coeffs = coeffs.AGC_spatial_FIR;
% Just mix in some left and right neighbors like in book figure 19.6:
stage_state = ...
FIR_coeffs(1) * stage_state([1, 1:(end-1)], :) + ...
FIR_coeffs(2) * stage_state + ...
FIR_coeffs(3) * stage_state([2:end, end], :);