comparison trunk/matlab/bmm/carfac/CARFAC_Design.m @ 565:3e2e0ab4f708

Major update to how the DOHC works; like in recent book OHC chapter; Design Doc update (a bit)
author dicklyon@google.com
date Thu, 24 May 2012 22:26:56 +0000
parents fb602edc2d55
children e4c2162baca8
comparison
equal deleted inserted replaced
564:9c4c3675c3f8 565:3e2e0ab4f708
50 fs = 22050; 50 fs = 22050;
51 end 51 end
52 52
53 if nargin < 3 53 if nargin < 3
54 CF_CAR_params = struct( ... 54 CF_CAR_params = struct( ...
55 'velocity_scale', 0.2, ... % for the "cubic" velocity nonlinearity 55 'velocity_scale', 0.05, ... % for the velocity nonlinearity
56 'v_offset', 0.04, ... % offset gives a quadratic part 56 'v_offset', 0.04, ... % offset gives a quadratic part
57 'v2_corner', 0.2, ... % corner for essential nonlin 57 'v2_corner', 0.2, ... % corner for essential nonlin
58 'v_damp_max', 0.01, ... % damping delta damping from velocity nonlin
59 'min_zeta', 0.10, ... % minimum damping factor in mid-freq channels 58 'min_zeta', 0.10, ... % minimum damping factor in mid-freq channels
59 'max_zeta', 0.35, ... % maximum damping factor in mid-freq channels
60 'first_pole_theta', 0.85*pi, ... 60 'first_pole_theta', 0.85*pi, ...
61 'zero_ratio', sqrt(2), ... % how far zero is above pole 61 'zero_ratio', sqrt(2), ... % how far zero is above pole
62 'high_f_damping_compression', 0.5, ... % 0 to 1 to compress zeta 62 'high_f_damping_compression', 0.5, ... % 0 to 1 to compress zeta
63 'ERB_per_step', 0.5, ... % assume G&M's ERB formula 63 'ERB_per_step', 0.5, ... % assume G&M's ERB formula
64 'min_pole_Hz', 30, ... 64 'min_pole_Hz', 30, ...
69 if nargin < 4 69 if nargin < 4
70 CF_AGC_params = struct( ... 70 CF_AGC_params = struct( ...
71 'n_stages', 4, ... 71 'n_stages', 4, ...
72 'time_constants', [1, 4, 16, 64]*0.002, ... 72 'time_constants', [1, 4, 16, 64]*0.002, ...
73 'AGC_stage_gain', 2, ... % gain from each stage to next slower stage 73 'AGC_stage_gain', 2, ... % gain from each stage to next slower stage
74 'decimation', [4, 2, 2, 2], ... % how often to update the AGC states 74 'decimation', [8, 2, 2, 2], ... % how often to update the AGC states
75 'AGC1_scales', [1.0, 1.4, 2.0, 2.8], ... % in units of channels 75 'AGC1_scales', [1.0, 1.4, 2.0, 2.8], ... % in units of channels
76 'AGC2_scales', [1.6, 2.25, 3.2, 4.5], ... % spread more toward base 76 'AGC2_scales', [1.6, 2.25, 3.2, 4.5], ... % spread more toward base
77 'detect_scale', 0.25, ... % the desired damping range
78 'AGC_mix_coeff', 0.5); 77 'AGC_mix_coeff', 0.5);
79 end 78 end
80 79
81 if nargin < 5 80 if nargin < 5
82 % HACK: these constant control the defaults 81 % HACK: these constant control the defaults
83 one_cap = 0; % bool; 0 for new two-cap hack 82 one_cap = 0; % bool; 0 for new two-cap hack
84 just_hwr = 0; % book; 0 for normal/fancy IHC; 1 for HWR 83 just_hwr = 0; % book; 0 for normal/fancy IHC; 1 for HWR
85 if just_hwr 84 if just_hwr
86 CF_IHC_params = struct('just_hwr', 1); % just a simple HWR 85 CF_IHC_params = struct('just_hwr', 1, ... % just a simple HWR
86 'ac_corner_Hz', 20);
87 else 87 else
88 if one_cap 88 if one_cap
89 CF_IHC_params = struct( ... 89 CF_IHC_params = struct( ...
90 'just_hwr', just_hwr, ... % not just a simple HWR 90 'just_hwr', just_hwr, ... % not just a simple HWR
91 'one_cap', one_cap, ... % bool; 0 for new two-cap hack 91 'one_cap', one_cap, ... % bool; 0 for new two-cap hack
92 'tau_lpf', 0.000080, ... % 80 microseconds smoothing twice 92 'tau_lpf', 0.000080, ... % 80 microseconds smoothing twice
93 'tau_out', 0.0005, ... % depletion tau is pretty fast 93 'tau_out', 0.0005, ... % depletion tau is pretty fast
94 'tau_in', 0.010 ); % recovery tau is slower 94 'tau_in', 0.010, ... % recovery tau is slower
95 'ac_corner_Hz', 20);
95 else 96 else
96 CF_IHC_params = struct( ... 97 CF_IHC_params = struct( ...
97 'just_hwr', just_hwr, ... % not just a simple HWR 98 'just_hwr', just_hwr, ... % not just a simple HWR
98 'one_cap', one_cap, ... % bool; 0 for new two-cap hack 99 'one_cap', one_cap, ... % bool; 0 for new two-cap hack
99 'tau_lpf', 0.000080, ... % 80 microseconds smoothing twice 100 'tau_lpf', 0.000080, ... % 80 microseconds smoothing twice
100 'tau1_out', 0.010, ... % depletion tau is pretty fast 101 'tau1_out', 0.010, ... % depletion tau is pretty fast
101 'tau1_in', 0.020, ... % recovery tau is slower 102 'tau1_in', 0.020, ... % recovery tau is slower
102 'tau2_out', 0.0025, ... % depletion tau is pretty fast 103 'tau2_out', 0.0025, ... % depletion tau is pretty fast
103 'tau2_in', 0.005 ); % recovery tau is slower 104 'tau2_in', 0.005, ... % recovery tau is slower
105 'ac_corner_Hz', 20);
104 end 106 end
105 end 107 end
106 end 108 end
107 109
108 110
162 164
163 CAR_coeffs = struct( ... 165 CAR_coeffs = struct( ...
164 'n_ch', n_ch, ... 166 'n_ch', n_ch, ...
165 'velocity_scale', CAR_params.velocity_scale, ... 167 'velocity_scale', CAR_params.velocity_scale, ...
166 'v_offset', CAR_params.v_offset, ... 168 'v_offset', CAR_params.v_offset, ...
167 'v2_corner', CAR_params.v2_corner, ... 169 'v2_corner', CAR_params.v2_corner ...
168 'v_damp_max', CAR_params.v_damp_max ...
169 ); 170 );
170 171
171 % don't really need these zero arrays, but it's a clue to what fields 172 % don't really need these zero arrays, but it's a clue to what fields
172 % and types are need in ohter language implementations: 173 % and types are need in ohter language implementations:
173 CAR_coeffs.r1_coeffs = zeros(n_ch, 1); 174 CAR_coeffs.r1_coeffs = zeros(n_ch, 1);
192 % different possible interpretations for min-damping r: 193 % different possible interpretations for min-damping r:
193 % r = exp(-theta * CF_CAR_params.min_zeta). 194 % r = exp(-theta * CF_CAR_params.min_zeta).
194 % Compress theta to give somewhat higher Q at highest thetas: 195 % Compress theta to give somewhat higher Q at highest thetas:
195 ff = CAR_params.high_f_damping_compression; % 0 to 1; typ. 0.5 196 ff = CAR_params.high_f_damping_compression; % 0 to 1; typ. 0.5
196 x = theta/pi; 197 x = theta/pi;
198
197 zr_coeffs = pi * (x - ff * x.^3); % when ff is 0, this is just theta, 199 zr_coeffs = pi * (x - ff * x.^3); % when ff is 0, this is just theta,
198 % and when ff is 1 it goes to zero at theta = pi. 200 % and when ff is 1 it goes to zero at theta = pi.
199 CAR_coeffs.zr_coeffs = zr_coeffs; % how r relates to zeta 201 max_zeta = CAR_params.max_zeta;
202 CAR_coeffs.r1_coeffs = (1 - zr_coeffs .* max_zeta); % "r1" for the max-damping condition
200 203
201 min_zeta = CAR_params.min_zeta; 204 min_zeta = CAR_params.min_zeta;
202 % increase the min damping where channels are spaced out more: 205 % Increase the min damping where channels are spaced out more, by pulling
203 206 % 25% of the way toward ERB_Hz/pole_freqs (close to 0.1 at high f)
204 min_zeta = min_zeta + 0.25*(ERB_Hz(pole_freqs, ... 207 min_zetas = min_zeta + 0.25*(ERB_Hz(pole_freqs, ...
205 CAR_params.ERB_break_freq, CAR_params.ERB_Q) ./ pole_freqs - min_zeta); 208 CAR_params.ERB_break_freq, CAR_params.ERB_Q) ./ pole_freqs - min_zeta);
206 r1 = (1 - zr_coeffs .* min_zeta); % "1" for the min-damping condition 209 CAR_coeffs.zr_coeffs = zr_coeffs .* ...
207 210 (max_zeta - min_zetas); % how r relates to undamping
208 CAR_coeffs.r1_coeffs = r1;
209 211
210 % undamped coupled-form coefficients: 212 % undamped coupled-form coefficients:
211 CAR_coeffs.a0_coeffs = a0; 213 CAR_coeffs.a0_coeffs = a0;
212 CAR_coeffs.c0_coeffs = c0; 214 CAR_coeffs.c0_coeffs = c0;
213 215
214 % the zeros follow via the h_coeffs 216 % the zeros follow via the h_coeffs
215 h = c0 .* f; 217 h = c0 .* f;
216 CAR_coeffs.h_coeffs = h; 218 CAR_coeffs.h_coeffs = h;
217 219
218 % for unity gain at min damping, radius r; only used in CARFAC_Init: 220 % for unity gain at min damping, radius r; only used in CARFAC_Init:
219 extra_damping = zeros(size(r1)); 221 relative_undamping = ones(n_ch, 1); % max undamping to start
220 % this function needs to take CAR_coeffs even if we haven't finished 222 % this function needs to take CAR_coeffs even if we haven't finished
221 % constucting it by putting in the g0_coeffs: 223 % constucting it by putting in the g0_coeffs:
222 CAR_coeffs.g0_coeffs = CARFAC_Stage_g(CAR_coeffs, extra_damping); 224 CAR_coeffs.g0_coeffs = CARFAC_Stage_g(CAR_coeffs, relative_undamping);
223 225
224 226
225 %% the AGC design coeffs: 227 %% the AGC design coeffs:
226 function AGC_coeffs = CARFAC_DesignAGC(AGC_params, fs, n_ch) 228 function AGC_coeffs = CARFAC_DesignAGC(AGC_params, fs, n_ch)
227 229
308 end 310 end
309 end 311 end
310 312
311 AGC_coeffs.AGC_gain = total_DC_gain; 313 AGC_coeffs.AGC_gain = total_DC_gain;
312 314
313 % adjust the detect_scale by the total DC gain of the AGC filters: 315 % adjust the detect_scale to be the reciprocal DC gain of the AGC filters:
314 AGC_coeffs.detect_scale = AGC_params.detect_scale / total_DC_gain; 316 AGC_coeffs.detect_scale = 1 / total_DC_gain;
315
316 % % print some results
317 AGC_coeffs
318 AGC_spatial_FIR = AGC_coeffs.AGC_spatial_FIR
319 AGC_spatial_iterations = AGC_coeffs.AGC_spatial_iterations
320 AGC_spatial_n_taps = AGC_coeffs.AGC_spatial_n_taps
321 317
322 318
323 %% 319 %%
324 function [FIR, OK] = Design_FIR_coeffs(n_taps, var, mn, n_iter) 320 function [FIR, OK] = Design_FIR_coeffs(n_taps, var, mn, n_iter)
325 % function [FIR, OK] = Design_FIR_coeffs(n_taps, spread_sq, delay, n_iter) 321 % function [FIR, OK] = Design_FIR_coeffs(n_taps, spread_sq, delay, n_iter)
353 IHC_coeffs = struct( ... 349 IHC_coeffs = struct( ...
354 'n_ch', n_ch, ... 350 'n_ch', n_ch, ...
355 'just_hwr', 1); 351 'just_hwr', 1);
356 else 352 else
357 if IHC_params.one_cap 353 if IHC_params.one_cap
358 ro = 1 / CARFAC_Detect(2); % output resistance 354 ro = 1 / CARFAC_Detect(10); % output resistance at a very high level
359 c = IHC_params.tau_out / ro; 355 c = IHC_params.tau_out / ro;
360 ri = IHC_params.tau_in / c; 356 ri = IHC_params.tau_in / c;
361 % to get steady-state average, double ro for 50% duty cycle 357 % to get steady-state average, double ro for 50% duty cycle
362 saturation_output = 1 / (2*ro + ri); 358 saturation_output = 1 / (2*ro + ri);
363 % also consider the zero-signal equilibrium: 359 % also consider the zero-signal equilibrium:
379 'cap_voltage', IHC_coeffs.rest_cap, ... 375 'cap_voltage', IHC_coeffs.rest_cap, ...
380 'lpf1_state', 0, ... 376 'lpf1_state', 0, ...
381 'lpf2_state', 0, ... 377 'lpf2_state', 0, ...
382 'ihc_accum', 0); 378 'ihc_accum', 0);
383 else 379 else
384 ro = 1 / CARFAC_Detect(2); % output resistance 380 ro = 1 / CARFAC_Detect(10); % output resistance at a very high level
385 c2 = IHC_params.tau2_out / ro; 381 c2 = IHC_params.tau2_out / ro;
386 r2 = IHC_params.tau2_in / c2; 382 r2 = IHC_params.tau2_in / c2;
387 c1 = IHC_params.tau1_out / r2; 383 c1 = IHC_params.tau1_out / r2;
388 r1 = IHC_params.tau1_in / c1; 384 r1 = IHC_params.tau1_in / c1;
389 % to get steady-state average, double ro for 50% duty cycle 385 % to get steady-state average, double ro for 50% duty cycle
413 'lpf1_state', 0, ... 409 'lpf1_state', 0, ...
414 'lpf2_state', 0, ... 410 'lpf2_state', 0, ...
415 'ihc_accum', 0); 411 'ihc_accum', 0);
416 end 412 end
417 end 413 end
414 % one more late addition that applies to all cases:
415 IHC_coeffs.ac_coeff = 2 * pi * IHC_params.ac_corner_Hz / fs;
418 416
419 %% 417 %%
420 % default design result, running this function with no args, should look 418 % default design result, running this function with no args, should look
421 % like this, before CARFAC_Init puts state storage into it: 419 % like this, before CARFAC_Init puts state storage into it:
422 % 420 %
423 % 421 %
424 % CF = CARFAC_Design 422 % CF = CARFAC_Design
425 % CF.CAR_params 423 % CAR_params = CF.CAR_params
426 % CF.AGC_params 424 % AGC_params = CF.AGC_params
427 % CF.CAR_coeffs 425 % IHC_params = CF.IHC_params
428 % CF.AGC_coeffs 426 % CAR_coeffs = CF.ears(1).CAR_coeffs
429 % CF.IHC_coeffs 427 % AGC_coeffs = CF.ears(1).AGC_coeffs
430 % CF = 428 % AGC_spatial_FIR = AGC_coeffs.AGC_spatial_FIR
429 % IHC_coeffs = CF.ears(1).IHC_coeffs
430
431 % CF =
431 % fs: 22050 432 % fs: 22050
432 % max_channels_per_octave: 12.2709 433 % max_channels_per_octave: 12.2709
433 % CAR_params: [1x1 struct] 434 % CAR_params: [1x1 struct]
434 % AGC_params: [1x1 struct] 435 % AGC_params: [1x1 struct]
435 % IHC_params: [1x1 struct] 436 % IHC_params: [1x1 struct]
436 % n_ch: 71 437 % n_ch: 71
437 % pole_freqs: [71x1 double] 438 % pole_freqs: [71x1 double]
438 % CAR_coeffs: [1x1 struct] 439 % ears: [1x1 struct]
439 % AGC_coeffs: [1x1 struct] 440 % n_ears: 1
440 % IHC_coeffs: [1x1 struct] 441 % CAR_params =
441 % n_ears: 0 442 % velocity_scale: 0.0500
442 % ans = 443 % v_offset: 0.0400
443 % velocity_scale: 0.2000
444 % v_offset: 0.0100
445 % v2_corner: 0.2000 444 % v2_corner: 0.2000
446 % v_damp_max: 0.0100
447 % min_zeta: 0.1000 445 % min_zeta: 0.1000
446 % max_zeta: 0.3500
448 % first_pole_theta: 2.6704 447 % first_pole_theta: 2.6704
449 % zero_ratio: 1.4142 448 % zero_ratio: 1.4142
450 % high_f_damping_compression: 0.5000 449 % high_f_damping_compression: 0.5000
451 % ERB_per_step: 0.5000 450 % ERB_per_step: 0.5000
452 % min_pole_Hz: 30 451 % min_pole_Hz: 30
453 % ERB_break_freq: 165.3000 452 % ERB_break_freq: 165.3000
454 % ERB_Q: 9.2645 453 % ERB_Q: 9.2645
455 % ans = 454 % AGC_params =
456 % n_stages: 4 455 % n_stages: 4
457 % time_constants: [0.0020 0.0080 0.0320 0.1280] 456 % time_constants: [0.0020 0.0080 0.0320 0.1280]
458 % AGC_stage_gain: 2 457 % AGC_stage_gain: 2
459 % decimation: [8 2 2 2] 458 % decimation: [8 2 2 2]
460 % AGC1_scales: [1 1.4000 2 2.8000] 459 % AGC1_scales: [1 1.4000 2 2.8000]
461 % AGC2_scales: [1.6000 2.2500 3.2000 4.5000] 460 % AGC2_scales: [1.6000 2.2500 3.2000 4.5000]
462 % detect_scale: 0.2500
463 % AGC_mix_coeff: 0.5000 461 % AGC_mix_coeff: 0.5000
464 % ans = 462 % IHC_params =
463 % just_hwr: 0
464 % one_cap: 0
465 % tau_lpf: 8.0000e-05
466 % tau1_out: 0.0100
467 % tau1_in: 0.0200
468 % tau2_out: 0.0025
469 % tau2_in: 0.0050
470 % ac_corner_Hz: 20
471 % CAR_coeffs =
465 % n_ch: 71 472 % n_ch: 71
466 % velocity_scale: 0.2000 473 % velocity_scale: 0.0500
467 % v_offset: 0.0100 474 % v_offset: 0.0400
468 % v2_corner: 0.2000 475 % v2_corner: 0.2000
469 % v_damp_max: 0.0100
470 % r1_coeffs: [71x1 double] 476 % r1_coeffs: [71x1 double]
471 % a0_coeffs: [71x1 double] 477 % a0_coeffs: [71x1 double]
472 % c0_coeffs: [71x1 double] 478 % c0_coeffs: [71x1 double]
473 % h_coeffs: [71x1 double] 479 % h_coeffs: [71x1 double]
474 % g0_coeffs: [71x1 double] 480 % g0_coeffs: [71x1 double]
475 % zr_coeffs: [71x1 double] 481 % zr_coeffs: [71x1 double]
476 % ans = 482 % AGC_coeffs =
477 % n_ch: 71 483 % n_ch: 71
478 % n_AGC_stages: 4 484 % n_AGC_stages: 4
479 % AGC_stage_gain: 2 485 % AGC_stage_gain: 2
480 % AGC_epsilon: [0.1659 0.0867 0.0443 0.0224] 486 % AGC_epsilon: [0.1659 0.0867 0.0443 0.0224]
481 % decimation: [8 2 2 2] 487 % decimation: [8 2 2 2]
484 % AGC_spatial_iterations: [1 1 1 1] 490 % AGC_spatial_iterations: [1 1 1 1]
485 % AGC_spatial_FIR: [3x4 double] 491 % AGC_spatial_FIR: [3x4 double]
486 % AGC_spatial_n_taps: [3 3 3 3] 492 % AGC_spatial_n_taps: [3 3 3 3]
487 % AGC_mix_coeffs: [0 0.0454 0.0227 0.0113] 493 % AGC_mix_coeffs: [0 0.0454 0.0227 0.0113]
488 % AGC_gain: 15 494 % AGC_gain: 15
489 % detect_scale: 0.0167 495 % detect_scale: 0.0667
490 % ans = 496 % AGC_spatial_FIR =
497 % 0.2744 0.2829 0.2972 0.2999
498 % 0.3423 0.3571 0.3512 0.3616
499 % 0.3832 0.3600 0.3516 0.3385
500 % IHC_coeffs =
491 % n_ch: 71 501 % n_ch: 71
492 % just_hwr: 0 502 % just_hwr: 0
493 % lpf_coeff: 0.4327 503 % lpf_coeff: 0.4327
494 % out1_rate: 0.0045 504 % out1_rate: 0.0045
495 % in1_rate: 0.0023 505 % in1_rate: 0.0023
496 % out2_rate: 0.0267 506 % out2_rate: 0.0199
497 % in2_rate: 0.0091 507 % in2_rate: 0.0091
498 % one_cap: 0 508 % one_cap: 0
499 % output_gain: 17.9162 509 % output_gain: 12.1185
500 % rest_output: 0.5240 510 % rest_output: 0.3791
501 % rest_cap2: 0.7421 511 % rest_cap2: 0.7938
502 % rest_cap1: 0.8281 512 % rest_cap1: 0.8625
513 % ac_coeff: 0.0057
514
515
516