annotate carfac/carfac_common.h @ 610:01986636257a

Second check-in of Alex Brandmeyer's C++ implementation of CARFAC. Addressed style issues and completed implementation of remaining functions. Still needs proper testing of the output stages against the MATLAB version, and runtime functions need improvements in efficiency.
author alexbrandmeyer
date Thu, 16 May 2013 17:33:23 +0000
parents aefe2ca0674f
children 0fbaf443ec82
rev   line source
alexbrandmeyer@609 1 //
alexbrandmeyer@609 2 // carfac_common.h
alexbrandmeyer@609 3 // CARFAC Open Source C++ Library
alexbrandmeyer@609 4 //
alexbrandmeyer@609 5 // Created by Alex Brandmeyer on 5/10/13.
alexbrandmeyer@609 6 //
alexbrandmeyer@609 7 // This C++ file is part of an implementation of Lyon's cochlear model:
alexbrandmeyer@609 8 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
alexbrandmeyer@609 9 // to supplement Lyon's upcoming book "Human and Machine Hearing"
alexbrandmeyer@609 10 //
alexbrandmeyer@609 11 // Licensed under the Apache License, Version 2.0 (the "License");
alexbrandmeyer@609 12 // you may not use this file except in compliance with the License.
alexbrandmeyer@609 13 // You may obtain a copy of the License at
alexbrandmeyer@609 14 //
alexbrandmeyer@609 15 // http://www.apache.org/licenses/LICENSE-2.0
alexbrandmeyer@609 16 //
alexbrandmeyer@609 17 // Unless required by applicable law or agreed to in writing, software
alexbrandmeyer@609 18 // distributed under the License is distributed on an "AS IS" BASIS,
alexbrandmeyer@609 19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
alexbrandmeyer@609 20 // See the License for the specific language governing permissions and
alexbrandmeyer@609 21 // limitations under the License.
alexbrandmeyer@609 22 //
alexbrandmeyer@609 23 // *****************************************************************************
alexbrandmeyer@609 24 // carfac_common.h
alexbrandmeyer@609 25 // *****************************************************************************
alexbrandmeyer@609 26 // This file contains the base level definitions and includes used within the
alexbrandmeyer@609 27 // CARFAC C++ library. It also defines some low level functions which are used
alexbrandmeyer@609 28 // during the calculation of the various coefficient sets required by the model.
alexbrandmeyer@609 29 //
alexbrandmeyer@609 30 // The current implementation of the library is dependent on the use of the
alexbrandmeyer@609 31 // Eigen C++ library for linear algebra. Specifically, Eigen Arrays are used
alexbrandmeyer@609 32 // extensively for coefficient wise operations during both the design and run
alexbrandmeyer@609 33 // stages of the model.
alexbrandmeyer@609 34 //
alexbrandmeyer@609 35 // The 'FPType' typedef is specified in this file in order to enable quick
alexbrandmeyer@609 36 // switching between precision levels (i.e. float vs. double) throughout the
alexbrandmeyer@609 37 // library. The remainder of the code uses this type for specifying floating
alexbrandmeyer@609 38 // point scalars.
alexbrandmeyer@609 39 //
alexbrandmeyer@609 40 // Two additional typedefs are defined for one and two dimensional arrays:
alexbrandmeyer@609 41 // FloatArray and FloatArray2d. These in turn make use of FPType so that the
alexbrandmeyer@609 42 // precision level across floating point data is consistent.
alexbrandmeyer@609 43 //
alexbrandmeyer@609 44 // The functions 'ERBHz' and 'CARFACDetect' are defined here, and are used
alexbrandmeyer@609 45 // during the design stage of a CARFAC model.
alexbrandmeyer@609 46
alexbrandmeyer@609 47 #ifndef CARFAC_Open_Source_C__Library_CARFACCommon_h
alexbrandmeyer@609 48 #define CARFAC_Open_Source_C__Library_CARFACCommon_h
alexbrandmeyer@609 49
alexbrandmeyer@610 50 // This section is where the base include operations for the CARFAC project
alexbrandmeyer@610 51 // occur.
alexbrandmeyer@610 52 // <iostream> is used for debugging output, but it could go in final version.
alexbrandmeyer@610 53 #include <iostream>
alexbrandmeyer@610 54 // <math.h> is used during coefficient calculations and runtime operations.
alexbrandmeyer@610 55 #include <math.h>
alexbrandmeyer@610 56 // <vector> is used in place of 2d Eigen Arrays for the AGC memory
alexbrandmeyer@610 57 #include <vector>
alexbrandmeyer@610 58 // The Eigen library is used extensively for 1d and 2d floating point arrays.
alexbrandmeyer@610 59 // For more information, see: http://eigen.tuxfamily.org
alexbrandmeyer@610 60 #include <Eigen/Dense>
alexbrandmeyer@609 61 using namespace Eigen;
alexbrandmeyer@609 62
alexbrandmeyer@610 63 // One constant value is defined here, but see my TODO regarding style issues.
alexbrandmeyer@610 64 // A fixed value of PI is defined throughout the project.
alexbrandmeyer@610 65 // TODO alexbrandmeyer: verify that this is OK with Google Style.
alexbrandmeyer@610 66 #define PI 3.141592653589793238
alexbrandmeyer@609 67
alexbrandmeyer@610 68 // Three typedefs are used for enabling quick switching of precision and array
alexbrandmeyer@610 69 // usage.
alexbrandmeyer@610 70 // The 'FPType' typedef is used to enable easy switching in precision level.
alexbrandmeyer@610 71 typedef double FPType;
alexbrandmeyer@610 72 // These are the two typedefs for Eigen floating point arrays.
alexbrandmeyer@610 73 typedef Eigen::Array<FPType, Dynamic, 1> FloatArray; // This is a 1d array.
alexbrandmeyer@610 74 typedef Eigen::Array<FPType, Dynamic, Dynamic> FloatArray2d; // This is 2d.
alexbrandmeyer@610 75
alexbrandmeyer@610 76 // Two psychoacoustics helper functions are defined here for use by the
alexbrandmeyer@610 77 // different processing stages in calculating coeffecients.
alexbrandmeyer@609 78
alexbrandmeyer@609 79 // Function: ERBHz
alexbrandmeyer@609 80 // Auditory filter nominal Equivalent Rectangular Bandwidth
alexbrandmeyer@609 81 // Ref: Glasberg and Moore: Hearing Research, 47 (1990), 103-138
alexbrandmeyer@609 82 FPType ERBHz(FPType cf_hz, FPType erb_break_freq, FPType erb_q);
alexbrandmeyer@609 83
alexbrandmeyer@609 84 // Function CARFACDetect
alexbrandmeyer@609 85 // TODO explain a bit more
alexbrandmeyer@609 86 FloatArray CARFACDetect (FloatArray x);
alexbrandmeyer@610 87
alexbrandmeyer@610 88 #endif