annotate trunk/C++/Ear.C @ 598:34dccba19c54

Fixed certain minor documentation bugs. Added the CAR::designFilters and CAR::stageG methods. These methods design the CAR.coeff coefficients. They have been compared to be the same as the matlab coefficients. An Ear is now contructed with a specific FS or, it uses the default. Added the PsychoAcoustics class to do ERB and Hz conversions. Added the EarTest.C main which allows the construction of an Ear class for testing.
author flatmax
date Wed, 20 Feb 2013 22:30:19 +0000
parents 359bcd461dd1
children b8a27b613867
rev   line source
flatmax@597 1 // Copyright 2013 Matt R. Flax <flatmax\@> All Rights Reserved.
flatmax@598 2 // Author Matt Flax <flatmax@>
flatmax@597 3 //
flatmax@597 4 // This C++ file is part of an implementation of Lyon's cochlear model:
flatmax@597 5 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
flatmax@597 6 // to supplement Lyon's upcoming book "Human and Machine Hearing"
flatmax@597 7 //
flatmax@597 8 // Licensed under the Apache License, Version 2.0 (the "License");
flatmax@597 9 // you may not use this file except in compliance with the License.
flatmax@597 10 // You may obtain a copy of the License at
flatmax@597 11 //
flatmax@597 12 // http://www.apache.org/licenses/LICENSE-2.0
flatmax@597 13 //
flatmax@597 14 // Unless required by applicable law or agreed to in writing, software
flatmax@597 15 // distributed under the License is distributed on an "AS IS" BASIS,
flatmax@597 16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
flatmax@597 17 // See the License for the specific language governing permissions and
flatmax@597 18 // limitations under the License.
flatmax@597 19 /**
flatmax@597 20 \author {Matt Flax <flatmax\@>}
flatmax@597 21 \date 2013.02.08
flatmax@597 22 */
flatmax@597 23
flatmax@597 24 #include "Ear.H"
flatmax@597 25
flatmax@598 26 Ear::Ear(FP_TYPE fs_) {
flatmax@598 27 fs=fs_; // set the specified sample rate
flatmax@598 28 design();
flatmax@597 29 }
flatmax@597 30
flatmax@598 31 Ear::Ear(void) {
flatmax@598 32 fs=DEFAULT_SAMPLERATE; // Use the default sample rate
flatmax@598 33 design();
flatmax@597 34 }
flatmax@598 35
flatmax@598 36 Ear::~Ear(void) {
flatmax@598 37 }
flatmax@598 38
flatmax@598 39 void Ear::design(void) {
flatmax@598 40
flatmax@598 41 // first figure out how many filter stages (PZFC/car.AC channels):
flatmax@598 42 FP_TYPE pole_Hz = car.param.first_pole_theta * fs / (2.*M_PI);
flatmax@598 43 n_ch = 0;
flatmax@598 44 while (pole_Hz > car.param.min_pole_Hz) {
flatmax@598 45 n_ch = n_ch + 1;
flatmax@598 46 pole_Hz = pole_Hz - car.param.ERB_per_step *
flatmax@598 47 PsychoAcoustics::Hz2ERB(pole_Hz, car.param.ERB_break_freq, car.param.ERB_Q);
flatmax@598 48 }
flatmax@598 49 // Now we have n_ch, the number of channels, so can make the array
flatmax@598 50 // and compute all the frequencies again to put into it:
flatmax@598 51 car.pole_freqs.resize(n_ch, NoChange);
flatmax@598 52 pole_Hz = car.param.first_pole_theta * fs / (2.*M_PI);
flatmax@598 53 for (int ch = 0; ch<n_ch; ch++) {
flatmax@598 54 car.pole_freqs[ch] = pole_Hz;
flatmax@598 55 pole_Hz = pole_Hz - car.param.ERB_per_step *
flatmax@598 56 PsychoAcoustics::Hz2ERB(pole_Hz, car.param.ERB_break_freq, car.param.ERB_Q);
flatmax@598 57 }
flatmax@598 58 // now we have n_ch, the number of channels, and pole_freqs array
flatmax@598 59
flatmax@598 60 max_channels_per_octave = (FP_TYPE)(log(2.) / log(car.pole_freqs[0]/car.pole_freqs[1]));
flatmax@598 61
flatmax@598 62 // convert to include an ear_array, each w coeffs and state...
flatmax@598 63 car.designFilters(fs, n_ch); //(car.param. fs, car.pole_freqs);
flatmax@598 64 //AGC.designAGC(CF_AGC_params, fs, n_ch);
flatmax@598 65 //IHC.designIHC(CF_IHC_params, fs, n_ch);
flatmax@598 66 }