Mercurial > hg > aimc
view trunk/matlab/bmm/carfac/CARFAC_AGC_Step.m @ 561:3dff17554c6d
add an ears array level everywhere
author | dicklyon@google.com |
---|---|
date | Mon, 23 Apr 2012 22:58:40 +0000 |
parents | 89b1fe5de60f |
children | 3e2e0ab4f708 |
line wrap: on
line source
% Copyright 2012, Google, Inc. % Author: Richard F. Lyon % % This Matlab file is part of an implementation of Lyon's cochlear model: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" % to supplement Lyon's upcoming book "Human and Machine Hearing" % % Licensed under the Apache License, Version 2.0 (the "License"); % you may not use this file except in compliance with the License. % You may obtain a copy of the License at % % http://www.apache.org/licenses/LICENSE-2.0 % % Unless required by applicable law or agreed to in writing, software % distributed under the License is distributed on an "AS IS" BASIS, % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % See the License for the specific language governing permissions and % limitations under the License. function [state, updated] = CARFAC_AGC_Step(coeffs, detects, state) % function [state, updated] = CARFAC_AGC_Step(coeffs, detects, state) % % one time step of the AGC state update; decimates internally stage = 1; AGC_in = coeffs.detect_scale * detects; [state, updated] = CARFAC_AGC_Recurse(coeffs, AGC_in, stage, state); function [state, updated] = CARFAC_AGC_Recurse(coeffs, AGC_in, ... stage, state) % function [state, updated] = CARFAC_AGC_Recurse(coeffs, AGC_in, ... % stage, state) % decim factor for this stage, relative to input or prev. stage: decim = coeffs.decimation(stage); % decim phase of this stage (do work on phase 0 only): decim_phase = mod(state(1).decim_phase(stage) + 1, decim); state.decim_phase(stage) = decim_phase; % accumulate input for this stage from detect or previous stage: state.input_accum(:, stage) = state.input_accum(:, stage) + AGC_in; % nothing else to do if it's not the right decim_phase if decim_phase == 0 % do lots of work, at decimated rate. % decimated inputs for this stage, and to be decimated more for next: AGC_in = state.input_accum(:, stage) / decim; state.input_accum(:, stage) = 0; % reset accumulator if stage < length(coeffs.decimation) % recurse to evaluate next stage(s) state = CARFAC_AGC_Recurse(coeffs, AGC_in, stage+1, state); % and add its output to this stage input, whether it updated or not: AGC_in = AGC_in + coeffs.AGC_stage_gain * state.AGC_memory(:, stage+1); end AGC_stage_state = state.AGC_memory(:, stage); % first-order recursive smoothing filter update, in time: AGC_stage_state = AGC_stage_state + ... coeffs.AGC_epsilon(stage) * (AGC_in - AGC_stage_state); % spatial smooth: AGC_stage_state = ... CARFAC_Spatial_Smooth(coeffs, stage, AGC_stage_state); % and store the state back (in C++, do it all in place?) state.AGC_memory(:, stage) = AGC_stage_state; updated = 1; % bool to say we have new state else updated = 0; end