annotate src/CAR.cpp @ 489:20de0b60b694 carfac_cpp

Added the initialization of g0, but parting from the MATLAB way of doing it. (temporary measure)
author Ulf.Hammarqvist@gmail.com
date Sat, 07 Apr 2012 09:52:04 +0000
parents af4bc33b2e1c
children 24828350536a
rev   line source
Ulf@477 1 #include "CAR.h"
Ulf@484 2 #include "CARFAC_common.h"
Ulf@487 3 #include "CARFAC.h"
Ulf@486 4 #include <cmath>
Ulf@477 5
Ulf@486 6 CAR_coefficients::CAR_coefficients(CAR_parameters* car_params, float fs,
Ulf@484 7 FloatArray pole_freqs){
Ulf@486 8
Ulf@486 9 float f = pow(car_params->zero_ratio_, 2) + 1;
Ulf@486 10
Ulf@488 11 // TODO: dirty FloatArray initialisation. Redo this later
Ulf@487 12 r1_coeffs_= pole_freqs;
Ulf@487 13 a0_coeffs_= pole_freqs;
Ulf@487 14 c0_coeffs_= pole_freqs;
Ulf@487 15 h_coeffs_= pole_freqs;
Ulf@487 16 g0_coeffs_= pole_freqs;
Ulf@487 17 zr_coeffs_= pole_freqs;
Ulf@487 18
Ulf@486 19 FloatArray theta = pole_freqs;
Ulf@486 20
Ulf@487 21 float min_zeta_mod;
Ulf@487 22 float x;
Ulf@487 23 float ff = car_params->high_f_damping_compression_;
Ulf@487 24
Ulf@488 25 // TODO: temp loop until we get eigen in (or we just leave it like this)
Ulf@488 26 for(float i=0; i<pole_freqs.size(); i++){
Ulf@486 27 theta[i] *= (2*kPi*fs); // scalar mult.
Ulf@487 28 c0_coeffs_[i] = sin(theta[i]);
Ulf@487 29 a0_coeffs_[i] = cos(theta[i]);
Ulf@487 30
Ulf@487 31 x = theta[i]/kPi;
Ulf@487 32 zr_coeffs_[i] = kPi * (x - ff * x*x*x);
Ulf@487 33
Ulf@487 34 min_zeta_mod = (car_params->min_zeta_ + 0.25 *
Ulf@487 35 (CARFAC::ERB_Hz(pole_freqs[i])/pole_freqs[i]-car_params->min_zeta_));
Ulf@487 36 r1_coeffs_[i] = 1-zr_coeffs_[i]*min_zeta_mod;
Ulf@487 37
Ulf@487 38 h_coeffs_[i] = c0_coeffs_[i] * f;
Ulf@488 39
Ulf@489 40 //TODO: g0_coeffs_ calculated here for now. Let's talk about this, need
Ulf@489 41 // to see the whole picture of what makes sense.
Ulf@489 42 // Related: I believe CAR, IHC and AGC classes would be beneficial!
Ulf@489 43 float tmp = 1 - 2*r1_coeffs_[i]*a0_coeffs_[i] + r1_coeffs_[i]*r1_coeffs_[i];
Ulf@489 44 g0_coeffs_[i] = tmp / ( tmp + h_coeffs_[i]*r1_coeffs_[i]*c0_coeffs_[i]);
Ulf@486 45 }
Ulf@486 46
Ulf@477 47 }
Ulf@477 48
Ulf@484 49 CAR_coefficients::~CAR_coefficients(){
Ulf@483 50 // TODO Auto-generated destructor stub
Ulf@477 51 }