annotate carfac/carfac_common.cc @ 626:586b0677aae8
Fourth revision of Alex Brandmeyer's C++ implementation. Fixed more style issues, changed AGC structures to vectors, replaced FloatArray2d with vector<FloatArray>, implemented first tests using GTest to verify coefficients and monaural output against Matlab values (stored in aimc/carfac/test_data/). To run tests, change the path stored in carfac_test.h in TEST_SRC_DIR. Added CARFAC_GenerateTestData to the Matlab branch, fixed stage indexing in CARFAC_Cross_Couple.m to reflect changes in AGCCoeffs and AGCState structs.
author |
alexbrandmeyer |
date |
Wed, 22 May 2013 21:30:02 +0000 |
parents |
0fbaf443ec82 |
children |
27f2d9b76075 |
rev |
line source |
alexbrandmeyer@609
|
1 //
|
alexbrandmeyer@609
|
2 // carfac_common.cc
|
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 #include "carfac_common.h"
|
alexbrandmeyer@609
|
24
|
alexbrandmeyer@626
|
25 FPType ERBHz (const FPType cf_hz, const FPType erb_break_freq,
|
alexbrandmeyer@626
|
26 const FPType erb_q) {
|
alexbrandmeyer@609
|
27 FPType erb;
|
alexbrandmeyer@609
|
28 erb = (erb_break_freq + cf_hz) / erb_q;
|
alexbrandmeyer@609
|
29 return erb;
|
alexbrandmeyer@609
|
30 }
|
alexbrandmeyer@609
|
31
|
alexbrandmeyer@626
|
32 FloatArray CARFACDetect (const FloatArray& x) {
|
alexbrandmeyer@610
|
33 FloatArray conductance, z, set;
|
alexbrandmeyer@609
|
34 FPType a = 0.175;
|
alexbrandmeyer@610
|
35 // This offsets the low-end tail into negative x territory.
|
alexbrandmeyer@610
|
36 // The parameter is adjusted for the book, to make the 20% DC response
|
alexbrandmeyer@610
|
37 // threshold at 0.1.
|
alexbrandmeyer@609
|
38 z = x + a;
|
alexbrandmeyer@610
|
39 // Zero is the final answer for many points.
|
alexbrandmeyer@626
|
40 conductance = (z < 0).select(0.0, (z*z*z) / (z*z*z + z*z + 0.1));
|
alexbrandmeyer@609
|
41 return conductance;
|
alexbrandmeyer@609
|
42 } |