changeset 548:ff12d0432d9c

Implemented all but g0 initialisation in CAR class
author Ulf.Hammarqvist@gmail.com
date Sat, 07 Apr 2012 09:35:10 +0000
parents cffa9e98eb45
children c23860d91135
files branches/carfac_cpp/src/CAR.cpp branches/carfac_cpp/src/CAR.h branches/carfac_cpp/src/CARFAC.cpp branches/carfac_cpp/src/CARFAC.h
diffstat 4 files changed, 40 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/branches/carfac_cpp/src/CAR.cpp	Sat Mar 31 18:15:17 2012 +0000
+++ b/branches/carfac_cpp/src/CAR.cpp	Sat Apr 07 09:35:10 2012 +0000
@@ -1,26 +1,45 @@
 #include "CAR.h"
 #include "CARFAC_common.h"
+#include "CARFAC.h"
 #include <cmath>
 
 CAR_coefficients::CAR_coefficients(CAR_parameters* car_params, float fs,
                                    FloatArray pole_freqs){
 
-  // initialisation of the FloatArray coefficients, if needed.
-
   float f = pow(car_params->zero_ratio_, 2) + 1;
 
+  // dirty FloatArray initialisation. Redo this later
+  r1_coeffs_= pole_freqs;
+  a0_coeffs_= pole_freqs;
+  c0_coeffs_= pole_freqs;
+  h_coeffs_= pole_freqs;
+  g0_coeffs_= pole_freqs;
+  zr_coeffs_= pole_freqs;
+
   FloatArray theta = pole_freqs;
-  FloatArray c0 = pole_freqs;
-  FloatArray a0 = pole_freqs;
 
-  // temp until we get eigen in
+  float min_zeta_mod;
+  float x;
+  float ff = car_params->high_f_damping_compression_;
+
+  // temp loop until we get eigen in
   for(float i=0; i<theta.size(); i++){
       theta[i] *= (2*kPi*fs); // scalar mult.
-      c0[i] = sin(theta[i]);
-      a0[i] = cos(theta[i]);
+      c0_coeffs_[i] = sin(theta[i]);
+      a0_coeffs_[i] = cos(theta[i]);
+
+      x = theta[i]/kPi;
+      zr_coeffs_[i] = kPi * (x - ff * x*x*x);
+
+      min_zeta_mod = (car_params->min_zeta_ + 0.25 *
+          (CARFAC::ERB_Hz(pole_freqs[i])/pole_freqs[i]-car_params->min_zeta_));
+
+      r1_coeffs_[i] = 1-zr_coeffs_[i]*min_zeta_mod;
+
+      h_coeffs_[i] = c0_coeffs_[i] * f;
   }
 
-  // etc
+  // g0_coeffs_[i] = ... TODO: restructure this!
 
 }
 
--- a/branches/carfac_cpp/src/CAR.h	Sat Mar 31 18:15:17 2012 +0000
+++ b/branches/carfac_cpp/src/CAR.h	Sat Apr 07 09:35:10 2012 +0000
@@ -41,11 +41,12 @@
   CAR_coefficients(CAR_parameters*, float, FloatArray);
   virtual ~CAR_coefficients();
 
-  FloatArray r1_coeffs;
-  FloatArray a0_coeffs;
-  FloatArray c0_coeffs;
-  FloatArray h_coeffs;
-  FloatArray g0_coeffs;
+  FloatArray r1_coeffs_;
+  FloatArray a0_coeffs_;
+  FloatArray c0_coeffs_;
+  FloatArray h_coeffs_;
+  FloatArray g0_coeffs_;
+  FloatArray zr_coeffs_;
 
 private:
   CAR_coefficients();
--- a/branches/carfac_cpp/src/CARFAC.cpp	Sat Mar 31 18:15:17 2012 +0000
+++ b/branches/carfac_cpp/src/CARFAC.cpp	Sat Apr 07 09:35:10 2012 +0000
@@ -38,9 +38,15 @@
   agc_coeffs_->detect_scale_ = agc_params_->detect_scale_ /
                                (ihc_coeffs_->saturation_output_ *
                                agc_coeffs_->agc_gain_);
+
+
 }
 
 //move this somewhere else?
+
+float CARFAC::ERB_Hz(float cf_hz){
+  return ERB_Hz(cf_hz, 1000/4.37, 1000/(24.7*4.37));
+} // is it really intentional to use this default value thing in matlab code?
 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){
   return (erb_break_freq + cf_hz) / erb_q;
 }
--- a/branches/carfac_cpp/src/CARFAC.h	Sat Mar 31 18:15:17 2012 +0000
+++ b/branches/carfac_cpp/src/CARFAC.h	Sat Apr 07 09:35:10 2012 +0000
@@ -13,6 +13,7 @@
 public:
   CARFAC(int, CAR_parameters*, IHC_parameters*, AGC_parameters*, float, float);
   virtual ~CARFAC();
+  static float ERB_Hz(float);
   static float ERB_Hz(float, float, float);
 
   float fs_;