Mercurial > hg > aimc
changeset 560:ab7fabe2af5d
fix some bugs I left in IHC one-cap and just-hwr modes
author | dicklyon@google.com |
---|---|
date | Mon, 23 Apr 2012 21:02:04 +0000 |
parents | 89b1fe5de60f |
children | 3dff17554c6d |
files | trunk/matlab/bmm/carfac/CARFAC_Cross_Couple.m trunk/matlab/bmm/carfac/CARFAC_Design.m trunk/matlab/bmm/carfac/CARFAC_IHC_Step.m trunk/matlab/bmm/carfac/CARFAC_Stage_g.m |
diffstat | 4 files changed, 30 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/matlab/bmm/carfac/CARFAC_Cross_Couple.m Tue Apr 10 05:40:18 2012 +0000 +++ b/trunk/matlab/bmm/carfac/CARFAC_Cross_Couple.m Mon Apr 23 21:02:04 2012 +0000 @@ -1,28 +1,27 @@ function AGC_state = CARFAC_Cross_Couple(AGC_coeffs, AGC_state); n_ears = length(AGC_state); -mix_coeffs = AGC_coeffs.AGC_mix_coeffs; -n_stages = length(mix_coeffs); - -% now cross-ear mix the stages that updated (leading stages at phase 0): -for stage = 1:n_stages - if AGC_state(1).decim_phase(stage) > 0 - break % all recently updated stages are finished - else - mix_coeff = mix_coeffs(stage); - if mix_coeff > 0 % Typically stage 1 has 0 so no work on that one. - this_stage_sum = 0; - % sum up over the ears and get their mean: - for ear = 1:n_ears - stage_state = AGC_state(ear).AGC_memory(:, stage); - this_stage_sum = this_stage_sum + stage_state; - end - this_stage_mean = this_stage_sum / n_ears; - % now move them all toward the mean: - for ear = 1:n_ears - stage_state = AGC_state(ear).AGC_memory(:, stage); - AGC_state(ear).AGC_memory(:, stage) = ... - stage_state + mix_coeff * (this_stage_mean - stage_state); +if n_ears > 1 + % now cross-ear mix the stages that updated (leading stages at phase 0): + for stage = 1:AGC_coeffs.n_AGC_stages + if AGC_state(1).decim_phase(stage) > 0 + break % all recently updated stages are finished + else + mix_coeff = AGC_coeffs.AGC_mix_coeffs(stage); + if mix_coeff > 0 % Typically stage 1 has 0 so no work on that one. + this_stage_sum = 0; + % sum up over the ears and get their mean: + for ear = 1:n_ears + stage_state = AGC_state(ear).AGC_memory(:, stage); + this_stage_sum = this_stage_sum + stage_state; + end + this_stage_mean = this_stage_sum / n_ears; + % now move them all toward the mean: + for ear = 1:n_ears + stage_state = AGC_state(ear).AGC_memory(:, stage); + AGC_state(ear).AGC_memory(:, stage) = ... + stage_state + mix_coeff * (this_stage_mean - stage_state); + end end end end
--- a/trunk/matlab/bmm/carfac/CARFAC_Design.m Tue Apr 10 05:40:18 2012 +0000 +++ b/trunk/matlab/bmm/carfac/CARFAC_Design.m Mon Apr 23 21:02:04 2012 +0000 @@ -333,8 +333,9 @@ function IHC_coeffs = CARFAC_DesignIHC(IHC_params, fs, n_ch) if IHC_params.just_hwr - IHC_coeffs = struct('just_hwr', 1); - saturation_output = 10; % HACK: assume some max out + IHC_coeffs = struct( ... + 'n_ch', n_ch, ... + 'just_hwr', 1); else if IHC_params.one_cap ro = 1 / CARFAC_Detect(2); % output resistance @@ -346,7 +347,6 @@ r0 = 1 / CARFAC_Detect(0); current = 1 / (ri + r0); cap_voltage = 1 - current * ri; - IHC_coeffs.rest_output = IHC_out; IHC_coeffs = struct( ... 'n_ch', n_ch, ... 'just_hwr', 0, ... @@ -362,7 +362,8 @@ 'cap_voltage', IHC_coeffs.rest_cap, ... 'lpf1_state', 0, ... 'lpf2_state', 0, ... - 'ihc_accum', 0); else + 'ihc_accum', 0); + else ro = 1 / CARFAC_Detect(2); % output resistance c2 = IHC_params.tau2_out / ro; r2 = IHC_params.tau2_in / c2;
--- a/trunk/matlab/bmm/carfac/CARFAC_IHC_Step.m Tue Apr 10 05:40:18 2012 +0000 +++ b/trunk/matlab/bmm/carfac/CARFAC_IHC_Step.m Mon Apr 23 21:02:04 2012 +0000 @@ -26,7 +26,7 @@ just_hwr = coeffs.just_hwr; if just_hwr - ihc_out = max(0, filters_out); + ihc_out = min(2, max(0, filters_out)); % limit it for stability state.ihc_accum = state.ihc_accum + ihc_out; else conductance = CARFAC_Detect(filters_out); % detect with HWR or so @@ -48,13 +48,11 @@ % smooth it twice with LPF: + ihc_out = ihc_out * coeffs.output_gain; state.lpf1_state = state.lpf1_state + coeffs.lpf_coeff * ... (ihc_out - state.lpf1_state); - state.lpf2_state = state.lpf2_state + coeffs.lpf_coeff * ... (state.lpf1_state - state.lpf2_state); - - ihc_out = state.lpf2_state * coeffs.output_gain - coeffs.rest_output; - + ihc_out = state.lpf2_state - coeffs.rest_output; state.ihc_accum = state.ihc_accum + ihc_out; % for where decimated output is useful end
--- a/trunk/matlab/bmm/carfac/CARFAC_Stage_g.m Tue Apr 10 05:40:18 2012 +0000 +++ b/trunk/matlab/bmm/carfac/CARFAC_Stage_g.m Mon Apr 23 21:02:04 2012 +0000 @@ -26,5 +26,5 @@ c0 = CAR_coeffs.c0_coeffs; h = CAR_coeffs.h_coeffs; zr = CAR_coeffs.zr_coeffs; -r = r1 - zr.*extra_damping; % HACK??? or use sin(ff*theta) instead of c? +r = r1 - zr.*extra_damping; g = (1 - 2*r.*a0 + r.^2) ./ (1 - 2*r.*a0 + h.*r.*c0 + r.^2);