annotate matlab/bmm/carfac/CARFAC_Design.m @ 504:a0869cb1c99b

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 37c007925536
children db0e5e86fddd
rev   line source
tom@455 1 % Copyright 2012, Google, Inc.
tom@455 2 % Author: Richard F. Lyon
tom@455 3 %
tom@455 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
tom@455 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
tom@455 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
tom@455 7 %
tom@455 8 % Licensed under the Apache License, Version 2.0 (the "License");
tom@455 9 % you may not use this file except in compliance with the License.
tom@455 10 % You may obtain a copy of the License at
tom@455 11 %
tom@455 12 % http://www.apache.org/licenses/LICENSE-2.0
tom@455 13 %
tom@455 14 % Unless required by applicable law or agreed to in writing, software
tom@455 15 % distributed under the License is distributed on an "AS IS" BASIS,
tom@455 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tom@455 17 % See the License for the specific language governing permissions and
tom@455 18 % limitations under the License.
tom@455 19
dicklyon@500 20 function CF = CARFAC_Design(n_ears, fs, CF_CAR_params, CF_AGC_params, CF_IHC_params)
dicklyon@473 21 % function CF = CARFAC_Design(fs, CF_CAR_params, ...
tom@455 22 % CF_AGC_params, ERB_break_freq, ERB_Q, CF_IHC_params)
tom@455 23 %
tom@455 24 % This function designs the CARFAC (Cascade of Asymmetric Resonators with
tom@455 25 % Fast-Acting Compression); that is, it take bundles of parameters and
tom@455 26 % computes all the filter coefficients needed to run it.
tom@455 27 %
tom@455 28 % fs is sample rate (per second)
dicklyon@473 29 % CF_CAR_params bundles all the pole-zero filter cascade parameters
tom@455 30 % CF_AGC_params bundles all the automatic gain control parameters
tom@455 31 % CF_IHC_params bundles all the inner hair cell parameters
tom@455 32 %
tom@455 33 % See other functions for designing and characterizing the CARFAC:
tom@455 34 % [naps, CF] = CARFAC_Run(CF, input_waves)
tom@455 35 % transfns = CARFAC_Transfer_Functions(CF, to_channels, from_channels)
tom@455 36 %
tom@455 37 % Defaults to Glasberg & Moore's ERB curve:
tom@455 38 % ERB_break_freq = 1000/4.37; % 228.833
tom@455 39 % ERB_Q = 1000/(24.7*4.37); % 9.2645
tom@455 40 %
tom@455 41 % All args are defaultable; for sample/default args see the code; they
tom@455 42 % make 96 channels at default fs = 22050, 114 channels at 44100.
tom@455 43
dicklyon@500 44 if nargin < 1
dicklyon@500 45 n_ears = 1; % if more than 1, make them identical channels;
dicklyon@500 46 % then modify the design if necessary for different reasons
dicklyon@500 47 end
dicklyon@500 48
dicklyon@500 49 if nargin < 2
dicklyon@500 50 fs = 22050;
dicklyon@500 51 end
dicklyon@500 52
dicklyon@500 53 if nargin < 3
dicklyon@500 54 CF_CAR_params = struct( ...
dicklyon@504 55 'velocity_scale', 0.05, ... % for the velocity nonlinearity
dicklyon@502 56 'v_offset', 0.04, ... % offset gives a quadratic part
dicklyon@500 57 'v2_corner', 0.2, ... % corner for essential nonlin
dicklyon@500 58 'min_zeta', 0.10, ... % minimum damping factor in mid-freq channels
dicklyon@504 59 'max_zeta', 0.35, ... % maximum damping factor in mid-freq channels
dicklyon@500 60 'first_pole_theta', 0.85*pi, ...
dicklyon@500 61 'zero_ratio', sqrt(2), ... % how far zero is above pole
dicklyon@500 62 'high_f_damping_compression', 0.5, ... % 0 to 1 to compress zeta
dicklyon@500 63 'ERB_per_step', 0.5, ... % assume G&M's ERB formula
dicklyon@500 64 'min_pole_Hz', 30, ...
dicklyon@500 65 'ERB_break_freq', 165.3, ... % Greenwood map's break freq.
dicklyon@500 66 'ERB_Q', 1000/(24.7*4.37)); % Glasberg and Moore's high-cf ratio
dicklyon@500 67 end
dicklyon@500 68
dicklyon@492 69 if nargin < 4
dicklyon@500 70 CF_AGC_params = struct( ...
dicklyon@500 71 'n_stages', 4, ...
dicklyon@500 72 'time_constants', [1, 4, 16, 64]*0.002, ...
dicklyon@500 73 'AGC_stage_gain', 2, ... % gain from each stage to next slower stage
dicklyon@504 74 'decimation', [8, 2, 2, 2], ... % how often to update the AGC states
dicklyon@500 75 'AGC1_scales', [1.0, 1.4, 2.0, 2.8], ... % in units of channels
dicklyon@500 76 'AGC2_scales', [1.6, 2.25, 3.2, 4.5], ... % spread more toward base
dicklyon@500 77 'AGC_mix_coeff', 0.5);
dicklyon@500 78 end
dicklyon@500 79
dicklyon@500 80 if nargin < 5
tom@455 81 % HACK: these constant control the defaults
tom@455 82 one_cap = 0; % bool; 0 for new two-cap hack
tom@455 83 just_hwr = 0; % book; 0 for normal/fancy IHC; 1 for HWR
tom@455 84 if just_hwr
dicklyon@504 85 CF_IHC_params = struct('just_hwr', 1, ... % just a simple HWR
dicklyon@504 86 'ac_corner_Hz', 20);
tom@455 87 else
tom@455 88 if one_cap
tom@455 89 CF_IHC_params = struct( ...
dicklyon@462 90 'just_hwr', just_hwr, ... % not just a simple HWR
tom@455 91 'one_cap', one_cap, ... % bool; 0 for new two-cap hack
tom@455 92 'tau_lpf', 0.000080, ... % 80 microseconds smoothing twice
tom@455 93 'tau_out', 0.0005, ... % depletion tau is pretty fast
dicklyon@504 94 'tau_in', 0.010, ... % recovery tau is slower
dicklyon@504 95 'ac_corner_Hz', 20);
tom@455 96 else
tom@455 97 CF_IHC_params = struct( ...
dicklyon@462 98 'just_hwr', just_hwr, ... % not just a simple HWR
tom@455 99 'one_cap', one_cap, ... % bool; 0 for new two-cap hack
tom@455 100 'tau_lpf', 0.000080, ... % 80 microseconds smoothing twice
dicklyon@495 101 'tau1_out', 0.010, ... % depletion tau is pretty fast
tom@455 102 'tau1_in', 0.020, ... % recovery tau is slower
dicklyon@495 103 'tau2_out', 0.0025, ... % depletion tau is pretty fast
dicklyon@504 104 'tau2_in', 0.005, ... % recovery tau is slower
dicklyon@504 105 'ac_corner_Hz', 20);
tom@455 106 end
tom@455 107 end
tom@455 108 end
tom@455 109
tom@455 110
tom@455 111
tom@455 112 % first figure out how many filter stages (PZFC/CARFAC channels):
dicklyon@473 113 pole_Hz = CF_CAR_params.first_pole_theta * fs / (2*pi);
tom@455 114 n_ch = 0;
dicklyon@473 115 while pole_Hz > CF_CAR_params.min_pole_Hz
tom@455 116 n_ch = n_ch + 1;
dicklyon@473 117 pole_Hz = pole_Hz - CF_CAR_params.ERB_per_step * ...
dicklyon@492 118 ERB_Hz(pole_Hz, CF_CAR_params.ERB_break_freq, CF_CAR_params.ERB_Q);
tom@455 119 end
tom@455 120 % Now we have n_ch, the number of channels, so can make the array
tom@455 121 % and compute all the frequencies again to put into it:
tom@455 122 pole_freqs = zeros(n_ch, 1);
dicklyon@473 123 pole_Hz = CF_CAR_params.first_pole_theta * fs / (2*pi);
tom@455 124 for ch = 1:n_ch
tom@455 125 pole_freqs(ch) = pole_Hz;
dicklyon@473 126 pole_Hz = pole_Hz - CF_CAR_params.ERB_per_step * ...
dicklyon@492 127 ERB_Hz(pole_Hz, CF_CAR_params.ERB_break_freq, CF_CAR_params.ERB_Q);
tom@455 128 end
tom@455 129 % now we have n_ch, the number of channels, and pole_freqs array
tom@455 130
dicklyon@467 131 max_channels_per_octave = log(2) / log(pole_freqs(1)/pole_freqs(2));
dicklyon@467 132
dicklyon@500 133 % convert to include an ear_array, each w coeffs and state...
dicklyon@500 134 CAR_coeffs = CARFAC_DesignFilters(CF_CAR_params, fs, pole_freqs);
dicklyon@500 135 AGC_coeffs = CARFAC_DesignAGC(CF_AGC_params, fs, n_ch);
dicklyon@500 136 IHC_coeffs = CARFAC_DesignIHC(CF_IHC_params, fs, n_ch);
dicklyon@500 137 % copy same designed coeffs into each ear (can do differently in the
dicklyon@500 138 % future:
dicklyon@500 139 for ear = 1:n_ears
dicklyon@500 140 ears(ear).CAR_coeffs = CAR_coeffs;
dicklyon@500 141 ears(ear).AGC_coeffs = AGC_coeffs;
dicklyon@500 142 ears(ear).IHC_coeffs = IHC_coeffs;
dicklyon@500 143 end
dicklyon@500 144
tom@455 145 CF = struct( ...
tom@455 146 'fs', fs, ...
dicklyon@467 147 'max_channels_per_octave', max_channels_per_octave, ...
dicklyon@473 148 'CAR_params', CF_CAR_params, ...
tom@455 149 'AGC_params', CF_AGC_params, ...
tom@455 150 'IHC_params', CF_IHC_params, ...
tom@455 151 'n_ch', n_ch, ...
tom@455 152 'pole_freqs', pole_freqs, ...
dicklyon@500 153 'ears', ears, ...
dicklyon@500 154 'n_ears', n_ears );
tom@455 155
tom@455 156
dicklyon@473 157
tom@455 158 %% Design the filter coeffs:
dicklyon@473 159 function CAR_coeffs = CARFAC_DesignFilters(CAR_params, fs, pole_freqs)
tom@455 160
tom@455 161 n_ch = length(pole_freqs);
tom@455 162
tom@455 163 % the filter design coeffs:
tom@455 164
dicklyon@473 165 CAR_coeffs = struct( ...
dicklyon@473 166 'n_ch', n_ch, ...
dicklyon@473 167 'velocity_scale', CAR_params.velocity_scale, ...
dicklyon@473 168 'v_offset', CAR_params.v_offset, ...
dicklyon@504 169 'v2_corner', CAR_params.v2_corner ...
dicklyon@462 170 );
tom@455 171
dicklyon@498 172 % don't really need these zero arrays, but it's a clue to what fields
dicklyon@498 173 % and types are need in ohter language implementations:
dicklyon@473 174 CAR_coeffs.r1_coeffs = zeros(n_ch, 1);
dicklyon@473 175 CAR_coeffs.a0_coeffs = zeros(n_ch, 1);
dicklyon@473 176 CAR_coeffs.c0_coeffs = zeros(n_ch, 1);
dicklyon@473 177 CAR_coeffs.h_coeffs = zeros(n_ch, 1);
dicklyon@473 178 CAR_coeffs.g0_coeffs = zeros(n_ch, 1);
tom@455 179
tom@455 180 % zero_ratio comes in via h. In book's circuit D, zero_ratio is 1/sqrt(a),
tom@455 181 % and that a is here 1 / (1+f) where h = f*c.
tom@455 182 % solve for f: 1/zero_ratio^2 = 1 / (1+f)
tom@455 183 % zero_ratio^2 = 1+f => f = zero_ratio^2 - 1
dicklyon@473 184 f = CAR_params.zero_ratio^2 - 1; % nominally 1 for half-octave
tom@455 185
tom@455 186 % Make pole positions, s and c coeffs, h and g coeffs, etc.,
tom@455 187 % which mostly depend on the pole angle theta:
tom@455 188 theta = pole_freqs .* (2 * pi / fs);
tom@455 189
dicklyon@469 190 c0 = sin(theta);
dicklyon@469 191 a0 = cos(theta);
dicklyon@469 192
tom@455 193 % different possible interpretations for min-damping r:
dicklyon@473 194 % r = exp(-theta * CF_CAR_params.min_zeta).
dicklyon@469 195 % Compress theta to give somewhat higher Q at highest thetas:
dicklyon@473 196 ff = CAR_params.high_f_damping_compression; % 0 to 1; typ. 0.5
dicklyon@469 197 x = theta/pi;
dicklyon@504 198
dicklyon@469 199 zr_coeffs = pi * (x - ff * x.^3); % when ff is 0, this is just theta,
dicklyon@469 200 % and when ff is 1 it goes to zero at theta = pi.
dicklyon@504 201 max_zeta = CAR_params.max_zeta;
dicklyon@504 202 CAR_coeffs.r1_coeffs = (1 - zr_coeffs .* max_zeta); % "r1" for the max-damping condition
dicklyon@469 203
dicklyon@473 204 min_zeta = CAR_params.min_zeta;
dicklyon@504 205 % Increase the min damping where channels are spaced out more, by pulling
dicklyon@504 206 % 25% of the way toward ERB_Hz/pole_freqs (close to 0.1 at high f)
dicklyon@504 207 min_zetas = min_zeta + 0.25*(ERB_Hz(pole_freqs, ...
dicklyon@492 208 CAR_params.ERB_break_freq, CAR_params.ERB_Q) ./ pole_freqs - min_zeta);
dicklyon@504 209 CAR_coeffs.zr_coeffs = zr_coeffs .* ...
dicklyon@504 210 (max_zeta - min_zetas); % how r relates to undamping
tom@455 211
tom@455 212 % undamped coupled-form coefficients:
dicklyon@473 213 CAR_coeffs.a0_coeffs = a0;
dicklyon@473 214 CAR_coeffs.c0_coeffs = c0;
tom@455 215
tom@455 216 % the zeros follow via the h_coeffs
dicklyon@469 217 h = c0 .* f;
dicklyon@473 218 CAR_coeffs.h_coeffs = h;
tom@455 219
dicklyon@469 220 % for unity gain at min damping, radius r; only used in CARFAC_Init:
dicklyon@504 221 relative_undamping = ones(n_ch, 1); % max undamping to start
dicklyon@473 222 % this function needs to take CAR_coeffs even if we haven't finished
dicklyon@469 223 % constucting it by putting in the g0_coeffs:
dicklyon@504 224 CAR_coeffs.g0_coeffs = CARFAC_Stage_g(CAR_coeffs, relative_undamping);
tom@455 225
tom@455 226
tom@455 227 %% the AGC design coeffs:
dicklyon@473 228 function AGC_coeffs = CARFAC_DesignAGC(AGC_params, fs, n_ch)
tom@455 229
dicklyon@473 230 n_AGC_stages = AGC_params.n_stages;
dicklyon@473 231 AGC_coeffs = struct( ...
dicklyon@473 232 'n_ch', n_ch, ...
dicklyon@473 233 'n_AGC_stages', n_AGC_stages, ...
dicklyon@473 234 'AGC_stage_gain', AGC_params.AGC_stage_gain);
tom@455 235
tom@455 236 % AGC1 pass is smoothing from base toward apex;
dicklyon@498 237 % AGC2 pass is back, which is done first now (in double exp. version)
tom@455 238 AGC1_scales = AGC_params.AGC1_scales;
tom@455 239 AGC2_scales = AGC_params.AGC2_scales;
tom@455 240
tom@455 241 AGC_coeffs.AGC_epsilon = zeros(1, n_AGC_stages); % the 1/(tau*fs) roughly
dicklyon@462 242 decim = 1;
dicklyon@462 243 AGC_coeffs.decimation = AGC_params.decimation;
dicklyon@462 244
dicklyon@462 245 total_DC_gain = 0;
tom@455 246 for stage = 1:n_AGC_stages
dicklyon@464 247 tau = AGC_params.time_constants(stage); % time constant in seconds
dicklyon@464 248 decim = decim * AGC_params.decimation(stage); % net decim to this stage
tom@455 249 % epsilon is how much new input to take at each update step:
tom@455 250 AGC_coeffs.AGC_epsilon(stage) = 1 - exp(-decim / (tau * fs));
dicklyon@462 251 % effective number of smoothings in a time constant:
dicklyon@464 252 ntimes = tau * (fs / decim); % typically 5 to 50
dicklyon@463 253
dicklyon@463 254 % decide on target spread (variance) and delay (mean) of impulse
dicklyon@463 255 % response as a distribution to be convolved ntimes:
dicklyon@464 256 % TODO (dicklyon): specify spread and delay instead of scales???
dicklyon@463 257 delay = (AGC2_scales(stage) - AGC1_scales(stage)) / ntimes;
dicklyon@463 258 spread_sq = (AGC1_scales(stage)^2 + AGC2_scales(stage)^2) / ntimes;
dicklyon@463 259
dicklyon@500 260 % get pole positions to better match intended spread and delay of
dicklyon@464 261 % [[geometric distribution]] in each direction (see wikipedia)
dicklyon@463 262 u = 1 + 1 / spread_sq; % these are based on off-line algebra hacking.
dicklyon@463 263 p = u - sqrt(u^2 - 1); % pole that would give spread if used twice.
dicklyon@463 264 dp = delay * (1 - 2*p +p^2)/2;
dicklyon@463 265 polez1 = p - dp;
dicklyon@463 266 polez2 = p + dp;
dicklyon@462 267 AGC_coeffs.AGC_polez1(stage) = polez1;
dicklyon@462 268 AGC_coeffs.AGC_polez2(stage) = polez2;
dicklyon@462 269
dicklyon@464 270 % try a 3- or 5-tap FIR as an alternative to the double exponential:
dicklyon@464 271 n_taps = 0;
dicklyon@464 272 FIR_OK = 0;
dicklyon@464 273 n_iterations = 1;
dicklyon@464 274 while ~FIR_OK
dicklyon@464 275 switch n_taps
dicklyon@464 276 case 0
dicklyon@464 277 % first attempt a 3-point FIR to apply once:
dicklyon@464 278 n_taps = 3;
dicklyon@464 279 case 3
dicklyon@464 280 % second time through, go wider but stick to 1 iteration
dicklyon@464 281 n_taps = 5;
dicklyon@464 282 case 5
dicklyon@464 283 % apply FIR multiple times instead of going wider:
dicklyon@464 284 n_iterations = n_iterations + 1;
dicklyon@464 285 if n_iterations > 16
dicklyon@464 286 error('Too many n_iterations in CARFAC_DesignAGC');
dicklyon@464 287 end
dicklyon@464 288 otherwise
dicklyon@464 289 % to do other n_taps would need changes in CARFAC_Spatial_Smooth
dicklyon@464 290 % and in Design_FIR_coeffs
dicklyon@464 291 error('Bad n_taps in CARFAC_DesignAGC');
dicklyon@462 292 end
dicklyon@464 293 [AGC_spatial_FIR, FIR_OK] = Design_FIR_coeffs( ...
dicklyon@464 294 n_taps, spread_sq, delay, n_iterations);
dicklyon@462 295 end
dicklyon@464 296 % when FIR_OK, store the resulting FIR design in coeffs:
dicklyon@462 297 AGC_coeffs.AGC_spatial_iterations(stage) = n_iterations;
dicklyon@462 298 AGC_coeffs.AGC_spatial_FIR(:,stage) = AGC_spatial_FIR;
dicklyon@475 299 AGC_coeffs.AGC_spatial_n_taps(stage) = n_taps;
dicklyon@462 300
dicklyon@464 301 % accumulate DC gains from all the stages, accounting for stage_gain:
dicklyon@462 302 total_DC_gain = total_DC_gain + AGC_params.AGC_stage_gain^(stage-1);
dicklyon@462 303
dicklyon@464 304 % TODO (dicklyon) -- is this the best binaural mixing plan?
dicklyon@462 305 if stage == 1
dicklyon@462 306 AGC_coeffs.AGC_mix_coeffs(stage) = 0;
dicklyon@462 307 else
dicklyon@462 308 AGC_coeffs.AGC_mix_coeffs(stage) = AGC_params.AGC_mix_coeff / ...
dicklyon@462 309 (tau * (fs / decim));
dicklyon@462 310 end
tom@455 311 end
tom@455 312
dicklyon@463 313 AGC_coeffs.AGC_gain = total_DC_gain;
dicklyon@462 314
dicklyon@504 315 % adjust the detect_scale to be the reciprocal DC gain of the AGC filters:
dicklyon@504 316 AGC_coeffs.detect_scale = 1 / total_DC_gain;
dicklyon@464 317
dicklyon@464 318
dicklyon@464 319 %%
dicklyon@464 320 function [FIR, OK] = Design_FIR_coeffs(n_taps, var, mn, n_iter)
dicklyon@464 321 % function [FIR, OK] = Design_FIR_coeffs(n_taps, spread_sq, delay, n_iter)
dicklyon@464 322
dicklyon@464 323 % reduce mean and variance of smoothing distribution by n_iterations:
dicklyon@464 324 mn = mn / n_iter;
dicklyon@464 325 var = var / n_iter;
dicklyon@464 326 switch n_taps
dicklyon@464 327 case 3
dicklyon@464 328 % based on solving to match mean and variance of [a, 1-a-b, b]:
dicklyon@464 329 a = (var + mn*mn - mn) / 2;
dicklyon@464 330 b = (var + mn*mn + mn) / 2;
dicklyon@464 331 FIR = [a, 1 - a - b, b];
dicklyon@464 332 OK = FIR(2) >= 0.2;
dicklyon@464 333 case 5
dicklyon@464 334 % based on solving to match [a/2, a/2, 1-a-b, b/2, b/2]:
dicklyon@464 335 a = ((var + mn*mn)*2/5 - mn*2/3) / 2;
dicklyon@464 336 b = ((var + mn*mn)*2/5 + mn*2/3) / 2;
dicklyon@464 337 % first and last coeffs are implicitly duplicated to make 5-point FIR:
dicklyon@464 338 FIR = [a/2, 1 - a - b, b/2];
dicklyon@464 339 OK = FIR(2) >= 0.1;
dicklyon@464 340 otherwise
dicklyon@464 341 error('Bad n_taps in AGC_spatial_FIR');
dicklyon@464 342 end
dicklyon@462 343
tom@455 344
tom@455 345 %% the IHC design coeffs:
dicklyon@473 346 function IHC_coeffs = CARFAC_DesignIHC(IHC_params, fs, n_ch)
tom@455 347
tom@455 348 if IHC_params.just_hwr
dicklyon@500 349 IHC_coeffs = struct( ...
dicklyon@500 350 'n_ch', n_ch, ...
dicklyon@500 351 'just_hwr', 1);
tom@455 352 else
tom@455 353 if IHC_params.one_cap
dicklyon@504 354 ro = 1 / CARFAC_Detect(10); % output resistance at a very high level
dicklyon@495 355 c = IHC_params.tau_out / ro;
dicklyon@495 356 ri = IHC_params.tau_in / c;
dicklyon@495 357 % to get steady-state average, double ro for 50% duty cycle
dicklyon@495 358 saturation_output = 1 / (2*ro + ri);
dicklyon@495 359 % also consider the zero-signal equilibrium:
dicklyon@495 360 r0 = 1 / CARFAC_Detect(0);
dicklyon@495 361 current = 1 / (ri + r0);
dicklyon@495 362 cap_voltage = 1 - current * ri;
dicklyon@473 363 IHC_coeffs = struct( ...
dicklyon@473 364 'n_ch', n_ch, ...
tom@455 365 'just_hwr', 0, ...
tom@455 366 'lpf_coeff', 1 - exp(-1/(IHC_params.tau_lpf * fs)), ...
dicklyon@495 367 'out_rate', ro / (IHC_params.tau_out * fs), ...
tom@455 368 'in_rate', 1 / (IHC_params.tau_in * fs), ...
dicklyon@495 369 'one_cap', IHC_params.one_cap, ...
dicklyon@495 370 'output_gain', 1/ (saturation_output - current), ...
dicklyon@495 371 'rest_output', current / (saturation_output - current), ...
dicklyon@495 372 'rest_cap', cap_voltage);
dicklyon@495 373 % one-channel state for testing/verification:
dicklyon@495 374 IHC_state = struct( ...
dicklyon@495 375 'cap_voltage', IHC_coeffs.rest_cap, ...
dicklyon@495 376 'lpf1_state', 0, ...
dicklyon@495 377 'lpf2_state', 0, ...
dicklyon@500 378 'ihc_accum', 0);
dicklyon@499 379 else
dicklyon@504 380 ro = 1 / CARFAC_Detect(10); % output resistance at a very high level
dicklyon@495 381 c2 = IHC_params.tau2_out / ro;
dicklyon@495 382 r2 = IHC_params.tau2_in / c2;
dicklyon@495 383 c1 = IHC_params.tau1_out / r2;
dicklyon@495 384 r1 = IHC_params.tau1_in / c1;
dicklyon@495 385 % to get steady-state average, double ro for 50% duty cycle
dicklyon@495 386 saturation_output = 1 / (2*ro + r2 + r1);
dicklyon@495 387 % also consider the zero-signal equilibrium:
dicklyon@495 388 r0 = 1 / CARFAC_Detect(0);
dicklyon@495 389 current = 1 / (r1 + r2 + r0);
dicklyon@495 390 cap1_voltage = 1 - current * r1;
dicklyon@495 391 cap2_voltage = cap1_voltage - current * r2;
tom@455 392 IHC_coeffs = struct(...
dicklyon@473 393 'n_ch', n_ch, ...
tom@455 394 'just_hwr', 0, ...
tom@455 395 'lpf_coeff', 1 - exp(-1/(IHC_params.tau_lpf * fs)), ...
tom@455 396 'out1_rate', 1 / (IHC_params.tau1_out * fs), ...
tom@455 397 'in1_rate', 1 / (IHC_params.tau1_in * fs), ...
dicklyon@495 398 'out2_rate', ro / (IHC_params.tau2_out * fs), ...
tom@455 399 'in2_rate', 1 / (IHC_params.tau2_in * fs), ...
dicklyon@495 400 'one_cap', IHC_params.one_cap, ...
dicklyon@495 401 'output_gain', 1/ (saturation_output - current), ...
dicklyon@495 402 'rest_output', current / (saturation_output - current), ...
dicklyon@495 403 'rest_cap2', cap2_voltage, ...
dicklyon@495 404 'rest_cap1', cap1_voltage);
dicklyon@495 405 % one-channel state for testing/verification:
dicklyon@495 406 IHC_state = struct( ...
dicklyon@495 407 'cap1_voltage', IHC_coeffs.rest_cap1, ...
dicklyon@495 408 'cap2_voltage', IHC_coeffs.rest_cap2, ...
dicklyon@495 409 'lpf1_state', 0, ...
dicklyon@495 410 'lpf2_state', 0, ...
dicklyon@495 411 'ihc_accum', 0);
tom@455 412 end
tom@455 413 end
dicklyon@504 414 % one more late addition that applies to all cases:
dicklyon@504 415 IHC_coeffs.ac_coeff = 2 * pi * IHC_params.ac_corner_Hz / fs;
tom@455 416
tom@455 417 %%
tom@455 418 % default design result, running this function with no args, should look
tom@455 419 % like this, before CARFAC_Init puts state storage into it:
tom@455 420 %
dicklyon@462 421 %
tom@455 422 % CF = CARFAC_Design
dicklyon@504 423 % CAR_params = CF.CAR_params
dicklyon@504 424 % AGC_params = CF.AGC_params
dicklyon@504 425 % IHC_params = CF.IHC_params
dicklyon@504 426 % CAR_coeffs = CF.ears(1).CAR_coeffs
dicklyon@504 427 % AGC_coeffs = CF.ears(1).AGC_coeffs
dicklyon@504 428 % AGC_spatial_FIR = AGC_coeffs.AGC_spatial_FIR
dicklyon@504 429 % IHC_coeffs = CF.ears(1).IHC_coeffs
dicklyon@504 430
dicklyon@504 431 % CF =
dicklyon@469 432 % fs: 22050
dicklyon@495 433 % max_channels_per_octave: 12.2709
dicklyon@495 434 % CAR_params: [1x1 struct]
dicklyon@469 435 % AGC_params: [1x1 struct]
dicklyon@469 436 % IHC_params: [1x1 struct]
dicklyon@495 437 % n_ch: 71
dicklyon@495 438 % pole_freqs: [71x1 double]
dicklyon@504 439 % ears: [1x1 struct]
dicklyon@504 440 % n_ears: 1
dicklyon@504 441 % CAR_params =
dicklyon@504 442 % velocity_scale: 0.0500
dicklyon@504 443 % v_offset: 0.0400
dicklyon@469 444 % v2_corner: 0.2000
dicklyon@472 445 % min_zeta: 0.1000
dicklyon@504 446 % max_zeta: 0.3500
dicklyon@469 447 % first_pole_theta: 2.6704
dicklyon@469 448 % zero_ratio: 1.4142
dicklyon@469 449 % high_f_damping_compression: 0.5000
dicklyon@469 450 % ERB_per_step: 0.5000
dicklyon@469 451 % min_pole_Hz: 30
dicklyon@495 452 % ERB_break_freq: 165.3000
dicklyon@495 453 % ERB_Q: 9.2645
dicklyon@504 454 % AGC_params =
tom@455 455 % n_stages: 4
tom@455 456 % time_constants: [0.0020 0.0080 0.0320 0.1280]
tom@455 457 % AGC_stage_gain: 2
dicklyon@462 458 % decimation: [8 2 2 2]
dicklyon@495 459 % AGC1_scales: [1 1.4000 2 2.8000]
dicklyon@495 460 % AGC2_scales: [1.6000 2.2500 3.2000 4.5000]
dicklyon@469 461 % AGC_mix_coeff: 0.5000
dicklyon@504 462 % IHC_params =
dicklyon@504 463 % just_hwr: 0
dicklyon@504 464 % one_cap: 0
dicklyon@504 465 % tau_lpf: 8.0000e-05
dicklyon@504 466 % tau1_out: 0.0100
dicklyon@504 467 % tau1_in: 0.0200
dicklyon@504 468 % tau2_out: 0.0025
dicklyon@504 469 % tau2_in: 0.0050
dicklyon@504 470 % ac_corner_Hz: 20
dicklyon@504 471 % CAR_coeffs =
dicklyon@495 472 % n_ch: 71
dicklyon@504 473 % velocity_scale: 0.0500
dicklyon@504 474 % v_offset: 0.0400
dicklyon@462 475 % v2_corner: 0.2000
dicklyon@495 476 % r1_coeffs: [71x1 double]
dicklyon@495 477 % a0_coeffs: [71x1 double]
dicklyon@495 478 % c0_coeffs: [71x1 double]
dicklyon@495 479 % h_coeffs: [71x1 double]
dicklyon@495 480 % g0_coeffs: [71x1 double]
dicklyon@495 481 % zr_coeffs: [71x1 double]
dicklyon@504 482 % AGC_coeffs =
dicklyon@495 483 % n_ch: 71
dicklyon@495 484 % n_AGC_stages: 4
dicklyon@462 485 % AGC_stage_gain: 2
dicklyon@462 486 % AGC_epsilon: [0.1659 0.0867 0.0443 0.0224]
dicklyon@462 487 % decimation: [8 2 2 2]
dicklyon@495 488 % AGC_polez1: [0.1699 0.1780 0.1872 0.1903]
dicklyon@495 489 % AGC_polez2: [0.2388 0.2271 0.2216 0.2148]
dicklyon@495 490 % AGC_spatial_iterations: [1 1 1 1]
dicklyon@462 491 % AGC_spatial_FIR: [3x4 double]
dicklyon@495 492 % AGC_spatial_n_taps: [3 3 3 3]
dicklyon@469 493 % AGC_mix_coeffs: [0 0.0454 0.0227 0.0113]
dicklyon@462 494 % AGC_gain: 15
dicklyon@504 495 % detect_scale: 0.0667
dicklyon@504 496 % AGC_spatial_FIR =
dicklyon@504 497 % 0.2744 0.2829 0.2972 0.2999
dicklyon@504 498 % 0.3423 0.3571 0.3512 0.3616
dicklyon@504 499 % 0.3832 0.3600 0.3516 0.3385
dicklyon@504 500 % IHC_coeffs =
dicklyon@495 501 % n_ch: 71
dicklyon@495 502 % just_hwr: 0
dicklyon@495 503 % lpf_coeff: 0.4327
dicklyon@495 504 % out1_rate: 0.0045
dicklyon@495 505 % in1_rate: 0.0023
dicklyon@504 506 % out2_rate: 0.0199
dicklyon@495 507 % in2_rate: 0.0091
dicklyon@495 508 % one_cap: 0
dicklyon@504 509 % output_gain: 12.1185
dicklyon@504 510 % rest_output: 0.3791
dicklyon@504 511 % rest_cap2: 0.7938
dicklyon@504 512 % rest_cap1: 0.8625
dicklyon@504 513 % ac_coeff: 0.0057
dicklyon@504 514
dicklyon@504 515
dicklyon@504 516