annotate carfac/agc.h @ 662:7e18c84ca2b7

Small cleanup of eigen usage in SAI implementation.
author ronw@google.com
date Tue, 16 Jul 2013 19:56:11 +0000
parents e76951e4da20
children
rev   line source
alexbrandmeyer@643 1 //
alexbrandmeyer@643 2 // agc.h
alexbrandmeyer@643 3 // CARFAC Open Source C++ Library
alexbrandmeyer@643 4 //
alexbrandmeyer@643 5 // Created by Alex Brandmeyer on 5/30/13.
alexbrandmeyer@643 6 //
alexbrandmeyer@643 7 // This C++ file is part of an implementation of Lyon's cochlear model:
alexbrandmeyer@643 8 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
alexbrandmeyer@643 9 // to supplement Lyon's upcoming book "Human and Machine Hearing"
alexbrandmeyer@643 10 //
alexbrandmeyer@643 11 // Licensed under the Apache License, Version 2.0 (the "License");
alexbrandmeyer@643 12 // you may not use this file except in compliance with the License.
alexbrandmeyer@643 13 // You may obtain a copy of the License at
alexbrandmeyer@643 14 //
alexbrandmeyer@643 15 // http://www.apache.org/licenses/LICENSE-2.0
alexbrandmeyer@643 16 //
alexbrandmeyer@643 17 // Unless required by applicable law or agreed to in writing, software
alexbrandmeyer@643 18 // distributed under the License is distributed on an "AS IS" BASIS,
alexbrandmeyer@643 19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
alexbrandmeyer@643 20 // See the License for the specific language governing permissions and
alexbrandmeyer@643 21 // limitations under the License.
alexbrandmeyer@643 22
alexbrandmeyer@643 23 #ifndef CARFAC_AGC_H
alexbrandmeyer@643 24 #define CARFAC_AGC_H
alexbrandmeyer@643 25
alexbrandmeyer@643 26 #include <vector>
ronw@646 27
alexbrandmeyer@643 28 #include "common.h"
alexbrandmeyer@643 29
ronw@646 30 // Automatic gain control (AGC) parameters, which are used to design the AGC
ronw@646 31 // filters.
alexbrandmeyer@643 32 struct AGCParams {
alexbrandmeyer@643 33 AGCParams() {
alexbrandmeyer@643 34 num_stages = 4;
alexbrandmeyer@643 35 agc_stage_gain = 2.0;
alexbrandmeyer@643 36 time_constants.resize(num_stages);
alexbrandmeyer@643 37 agc1_scales.resize(num_stages);
alexbrandmeyer@643 38 agc2_scales.resize(num_stages);
alexbrandmeyer@643 39 agc1_scales[0] = 1.0;
alexbrandmeyer@643 40 agc2_scales[0] = 1.65;
alexbrandmeyer@643 41 time_constants[0] = 0.002;
alexbrandmeyer@643 42 for (int i = 1; i < num_stages; ++i) {
alexbrandmeyer@643 43 agc1_scales[i] = agc1_scales[i - 1] * sqrt(2.0);
alexbrandmeyer@643 44 agc2_scales[i] = agc2_scales[i - 1] * sqrt(2.0);
alexbrandmeyer@643 45 time_constants[i] = time_constants[i - 1] * 4.0;
alexbrandmeyer@643 46 }
alexbrandmeyer@643 47 decimation = {8, 2, 2, 2};
alexbrandmeyer@643 48 agc_mix_coeff = 0.5;
alexbrandmeyer@643 49 }
alexbrandmeyer@643 50 int num_stages;
alexbrandmeyer@643 51 FPType agc_stage_gain;
alexbrandmeyer@643 52 FPType agc_mix_coeff;
alexbrandmeyer@643 53 std::vector<FPType> time_constants;
alexbrandmeyer@643 54 std::vector<int> decimation;
alexbrandmeyer@643 55 std::vector<FPType> agc1_scales;
alexbrandmeyer@643 56 std::vector<FPType> agc2_scales;
alexbrandmeyer@643 57 };
alexbrandmeyer@643 58
ronw@646 59 // Automatic gain control filter coefficients, which are derived from a set of
ronw@646 60 // AGCParams.
alexbrandmeyer@643 61 struct AGCCoeffs {
alexbrandmeyer@643 62 int num_agc_stages;
alexbrandmeyer@643 63 FPType agc_stage_gain;
alexbrandmeyer@643 64 FPType agc_epsilon;
alexbrandmeyer@643 65 int decimation;
alexbrandmeyer@643 66 FPType agc_pole_z1;
alexbrandmeyer@643 67 FPType agc_pole_z2;
alexbrandmeyer@643 68 int agc_spatial_iterations;
alexbrandmeyer@643 69 FPType agc_spatial_fir_left;
alexbrandmeyer@643 70 FPType agc_spatial_fir_mid;
alexbrandmeyer@643 71 FPType agc_spatial_fir_right;
alexbrandmeyer@643 72 int agc_spatial_n_taps;
alexbrandmeyer@643 73 FPType agc_mix_coeffs;
alexbrandmeyer@643 74 FPType agc_gain;
alexbrandmeyer@643 75 FPType detect_scale;
alexbrandmeyer@643 76 FPType decim;
alexbrandmeyer@643 77 };
alexbrandmeyer@643 78
ronw@646 79 // Automatic gain control filter state.
alexbrandmeyer@643 80 struct AGCState {
alexbrandmeyer@643 81 ArrayX agc_memory;
alexbrandmeyer@643 82 ArrayX input_accum;
alexbrandmeyer@643 83 int decim_phase;
alexbrandmeyer@643 84 };
alexbrandmeyer@643 85
ronw@646 86 #endif // CARFAC_AGC_H