comparison trunk/src/Modules/BMM/ModuleGammatone.cc @ 290:e344ef4898b2

-Moved scripts to new scripts dir -Fixed a bug in the IIR gammatone gain that was causing a resonance at 3kHz -Changes HCL default for do_lowpass to true
author tomwalters
date Mon, 22 Feb 2010 12:42:47 +0000
parents 6cf55200a199
children 2d3cef76b073
comparison
equal deleted inserted replaced
289:6cf55200a199 290:e344ef4898b2
90 state_4_.resize(num_channels_); 90 state_4_.resize(num_channels_);
91 91
92 for (int ch = 0; ch < num_channels_; ++ch) { 92 for (int ch = 0; ch < num_channels_; ++ch) {
93 double cf = centre_frequencies_[ch]; 93 double cf = centre_frequencies_[ch];
94 double erb = ERBTools::Freq2ERBw(cf); 94 double erb = ERBTools::Freq2ERBw(cf);
95 // LOG_INFO("%e", erb);
95 96
96 // Sample interval 97 // Sample interval
97 double dt = 1.0f / input.sample_rate(); 98 double dt = 1.0f / input.sample_rate();
98 99
99 // Bandwidth parameter 100 // Bandwidth parameter
108 double cpt = cf * M_PI * dt; 109 double cpt = cf * M_PI * dt;
109 complex<double> exponent(0.0, 2.0 * cpt); 110 complex<double> exponent(0.0, 2.0 * cpt);
110 complex<double> ec = exp(2.0 * exponent); 111 complex<double> ec = exp(2.0 * exponent);
111 complex<double> two_cf_pi_t(2.0 * cpt, 0.0); 112 complex<double> two_cf_pi_t(2.0 * cpt, 0.0);
112 complex<double> two_pow(pow(2.0, (3.0 / 2.0)), 0.0); 113 complex<double> two_pow(pow(2.0, (3.0 / 2.0)), 0.0);
113 complex<double> p = -2.0 * ec * dt 114 complex<double> p1 = -2.0 * ec * dt;
114 + 2.0 * exp(-(b * dt) + exponent) * dt; 115 complex<double> p2 = 2.0 * exp(-(b * dt) + exponent) * dt;
115 complex<double> b_dt(b * dt, 0.0); 116 complex<double> b_dt(b * dt, 0.0);
116 117
117 double gain = abs( 118 double gain = abs(
118 (p * (cos(two_cf_pi_t) - sqrt(3.0 - two_pow) * sin(two_cf_pi_t))) 119 (p1 + p2 * (cos(two_cf_pi_t) - sqrt(3.0 - two_pow) * sin(two_cf_pi_t)))
119 * (p * (cos(two_cf_pi_t) + sqrt(3.0 - two_pow) * sin(two_cf_pi_t))) 120 * (p1 + p2 * (cos(two_cf_pi_t) + sqrt(3.0 - two_pow) * sin(two_cf_pi_t)))
120 * (p * (cos(two_cf_pi_t) - sqrt(3.0 + two_pow) * sin(two_cf_pi_t))) 121 * (p1 + p2 * (cos(two_cf_pi_t) - sqrt(3.0 + two_pow) * sin(two_cf_pi_t)))
121 * (p * (cos(two_cf_pi_t) + sqrt(3.0 + two_pow) * sin(two_cf_pi_t))) 122 * (p1 + p2 * (cos(two_cf_pi_t) + sqrt(3.0 + two_pow) * sin(two_cf_pi_t)))
122 / pow(-2.0 / exp(2.0 * b_dt) - 2.0 * ec + 2.0 * (1.0 + ec) 123 / pow((-2.0 / exp(2.0 * b_dt) - 2.0 * ec + 2.0 * (1.0 + ec)
123 / exp(b_dt), 4.0)); 124 / exp(b_dt)), 4));
125 LOG_INFO("%e", gain);
124 126
125 // The filter coefficients themselves: 127 // The filter coefficients themselves:
126 const int coeff_count = 3; 128 const int coeff_count = 3;
127 a_[ch].resize(coeff_count, 0.0f); 129 a_[ch].resize(coeff_count, 0.0f);
128 b1_[ch].resize(coeff_count, 0.0f); 130 b1_[ch].resize(coeff_count, 0.0f);