annotate trunk/carfac/carfac_common.cc @ 684:49af9a8d5a53

Initial translation of SAI code to C++. This only implements the simple (as opposed to the layered) SAI, as implemented in SAI_Run.m.
author ronw@google.com
date Fri, 31 May 2013 21:46:48 +0000
parents 7f424c1a8b78
children
rev   line source
alexbrandmeyer@620 1 //
alexbrandmeyer@620 2 // carfac_common.cc
alexbrandmeyer@620 3 // CARFAC Open Source C++ Library
alexbrandmeyer@620 4 //
alexbrandmeyer@620 5 // Created by Alex Brandmeyer on 5/10/13.
alexbrandmeyer@620 6 //
alexbrandmeyer@620 7 // This C++ file is part of an implementation of Lyon's cochlear model:
alexbrandmeyer@620 8 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
alexbrandmeyer@620 9 // to supplement Lyon's upcoming book "Human and Machine Hearing"
alexbrandmeyer@620 10 //
alexbrandmeyer@620 11 // Licensed under the Apache License, Version 2.0 (the "License");
alexbrandmeyer@620 12 // you may not use this file except in compliance with the License.
alexbrandmeyer@620 13 // You may obtain a copy of the License at
alexbrandmeyer@620 14 //
alexbrandmeyer@620 15 // http://www.apache.org/licenses/LICENSE-2.0
alexbrandmeyer@620 16 //
alexbrandmeyer@620 17 // Unless required by applicable law or agreed to in writing, software
alexbrandmeyer@620 18 // distributed under the License is distributed on an "AS IS" BASIS,
alexbrandmeyer@620 19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
alexbrandmeyer@620 20 // See the License for the specific language governing permissions and
alexbrandmeyer@620 21 // limitations under the License.
alexbrandmeyer@620 22
alexbrandmeyer@620 23 #include "carfac_common.h"
alexbrandmeyer@620 24
alexbrandmeyer@668 25 FPType ERBHz (const FPType cf_hz, const FPType erb_break_freq,
alexbrandmeyer@668 26 const FPType erb_q) {
alexbrandmeyer@678 27 return (erb_break_freq + cf_hz) / erb_q;
alexbrandmeyer@620 28 }
alexbrandmeyer@620 29
alexbrandmeyer@668 30 FloatArray CARFACDetect (const FloatArray& x) {
alexbrandmeyer@621 31 FloatArray conductance, z, set;
alexbrandmeyer@620 32 FPType a = 0.175;
alexbrandmeyer@621 33 // This offsets the low-end tail into negative x territory.
alexbrandmeyer@621 34 // The parameter is adjusted for the book, to make the 20% DC response
alexbrandmeyer@621 35 // threshold at 0.1.
alexbrandmeyer@620 36 z = x + a;
alexbrandmeyer@621 37 // Zero is the final answer for many points.
alexbrandmeyer@668 38 conductance = (z < 0).select(0.0, (z*z*z) / (z*z*z + z*z + 0.1));
alexbrandmeyer@620 39 return conductance;
alexbrandmeyer@620 40 }