comparison trunk/C++/CAR.C @ 600:b1cbc2617c7f

Updated Matrix resizing and Zeroing using rif@google's suggestions.
author flatmax
date Tue, 26 Feb 2013 10:43:26 +0000
parents 34dccba19c54
children 33c6f1921171
comparison
equal deleted inserted replaced
599:b4323584c9fa 600:b1cbc2617c7f
32 } 32 }
33 33
34 void CAR::designFilters(FP_TYPE fs, int n_ch) { 34 void CAR::designFilters(FP_TYPE fs, int n_ch) {
35 // don't really need these zero arrays, but it's a clue to what fields 35 // don't really need these zero arrays, but it's a clue to what fields
36 // and types are need in ohter language implementations: 36 // and types are need in ohter language implementations:
37 coeff.r1_coeffs.resize(n_ch, 1); coeff.r1_coeffs-=coeff.r1_coeffs; // resize and zero 37 coeff.r1_coeffs=Matrix<FP_TYPE, Dynamic, 1>::Zero(n_ch,1); // resize and zero
38 coeff.a0_coeffs.resize(n_ch, 1); coeff.a0_coeffs-=coeff.a0_coeffs; 38 coeff.a0_coeffs=Matrix<FP_TYPE, Dynamic, 1>::Zero(n_ch,1);
39 coeff.c0_coeffs.resize(n_ch, 1); coeff.c0_coeffs-=coeff.c0_coeffs; 39 coeff.c0_coeffs=Matrix<FP_TYPE, Dynamic, 1>::Zero(n_ch,1);
40 coeff.h_coeffs.resize(n_ch, 1); coeff.h_coeffs-=coeff.h_coeffs; 40 coeff.h_coeffs=Matrix<FP_TYPE, Dynamic, 1>::Zero(n_ch,1);
41 coeff.g0_coeffs.resize(n_ch, 1); coeff.g0_coeffs-=coeff.g0_coeffs; 41 coeff.g0_coeffs=Matrix<FP_TYPE, Dynamic, 1>::Zero(n_ch,1);
42 // zr_coeffs is not zeroed ... perhaps it should be ? 42 // zr_coeffs is not zeroed ... perhaps it should be ?
43 43
44 // zero_ratio comes in via h. In book's circuit D, zero_ratio is 1/sqrt(a), 44 // zero_ratio comes in via h. In book's circuit D, zero_ratio is 1/sqrt(a),
45 // and that a is here 1 / (1+f) where h = f*c. 45 // and that a is here 1 / (1+f) where h = f*c.
46 // solve for f: 1/zero_ratio^2 = 1 / (1+f) 46 // solve for f: 1/zero_ratio^2 = 1 / (1+f)
74 // the zeros follow via the h_coeffs 74 // the zeros follow via the h_coeffs
75 coeff.h_coeffs = coeff.c0_coeffs * f; 75 coeff.h_coeffs = coeff.c0_coeffs * f;
76 76
77 // for unity gain at min damping, radius r; only used in CARFAC_Init: 77 // for unity gain at min damping, radius r; only used in CARFAC_Init:
78 Array<FP_TYPE, Dynamic,1> relative_undamping(n_ch, 1); 78 Array<FP_TYPE, Dynamic,1> relative_undamping(n_ch, 1);
79 relative_undamping=(relative_undamping-=relative_undamping).cos();// what is an efficient way to set a matrix to 1. ? As this is in a design phase, I will leave it for now 79 relative_undamping=Array<FP_TYPE, Dynamic, 1>::Zero(n_ch, 1).cos();
80 80
81 // this function needs to take CAR_coeffs even if we haven't finished 81 // this function needs to take CAR_coeffs even if we haven't finished
82 // constucting it by putting in the g0_coeffs: 82 // constucting it by putting in the g0_coeffs:
83 coeff.g0_coeffs = stageG(relative_undamping); 83 coeff.g0_coeffs = stageG(relative_undamping);
84
85 } 84 }
86 85
87 Array<FP_TYPE, Dynamic, 1> CAR::stageG(Array<FP_TYPE, Dynamic, 1> &relative_undamping) { 86 Array<FP_TYPE, Dynamic, 1> CAR::stageG(Array<FP_TYPE, Dynamic, 1> &relative_undamping) {
88 // at max damping 87 // at max damping
89 Array<FP_TYPE, Dynamic, 1> r = coeff.r1_coeffs.array() + coeff.zr_coeffs.array() * relative_undamping; 88 Array<FP_TYPE, Dynamic, 1> r = coeff.r1_coeffs.array() + coeff.zr_coeffs.array() * relative_undamping;