annotate matlab/bmm/carfac/CARFAC_CAR_Step.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
rev   line source
dicklyon@473 1 % Copyright 2012, Google, Inc.
dicklyon@473 2 % Author: Richard F. Lyon
dicklyon@473 3 %
dicklyon@473 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
dicklyon@473 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
dicklyon@473 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
dicklyon@473 7 %
dicklyon@473 8 % Licensed under the Apache License, Version 2.0 (the "License");
dicklyon@473 9 % you may not use this file except in compliance with the License.
dicklyon@473 10 % You may obtain a copy of the License at
dicklyon@473 11 %
dicklyon@473 12 % http://www.apache.org/licenses/LICENSE-2.0
dicklyon@473 13 %
dicklyon@473 14 % Unless required by applicable law or agreed to in writing, software
dicklyon@473 15 % distributed under the License is distributed on an "AS IS" BASIS,
dicklyon@473 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dicklyon@473 17 % See the License for the specific language governing permissions and
dicklyon@473 18 % limitations under the License.
dicklyon@473 19
dicklyon@504 20 function [car_out, state] = CARFAC_CAR_Step(x_in, CAR_coeffs, state)
dicklyon@473 21 % function [zY, state] = CARFAC_CAR_Step(x_in, CAR_coeffs, state)
dicklyon@473 22 %
dicklyon@473 23 % One sample-time update step for the filter part of the CARFAC.
dicklyon@473 24
dicklyon@473 25 % Most of the update is parallel; finally we ripple inputs at the end.
dicklyon@473 26
dicklyon@504 27
dicklyon@504 28 % do the DOHC stuff:
dicklyon@504 29
dicklyon@504 30 g = state.g_memory + state.dg_memory; % interp g
dicklyon@504 31 zB = state.zB_memory + state.dzB_memory; % AGC interpolation state
dicklyon@504 32 % update the nonlinear function of "velocity", and zA (delay of z2):
dicklyon@473 33 zA = state.zA_memory;
dicklyon@504 34 v = state.z2_memory - zA;
dicklyon@504 35 % nlf = CARFAC_OHC_NLF(v .* widen, CAR_coeffs); % widen v with feedback
dicklyon@504 36 nlf = CARFAC_OHC_NLF(v, CAR_coeffs);
dicklyon@504 37 % zB * nfl is "undamping" delta r:
dicklyon@504 38 r = CAR_coeffs.r1_coeffs + zB .* nlf;
dicklyon@504 39 zA = state.z2_memory;
dicklyon@473 40
dicklyon@473 41
dicklyon@473 42 % now reduce state by r and rotate with the fixed cos/sin coeffs:
dicklyon@473 43 z1 = r .* (CAR_coeffs.a0_coeffs .* state.z1_memory - ...
dicklyon@473 44 CAR_coeffs.c0_coeffs .* state.z2_memory);
dicklyon@473 45 % z1 = z1 + inputs;
dicklyon@473 46 z2 = r .* (CAR_coeffs.c0_coeffs .* state.z1_memory + ...
dicklyon@473 47 CAR_coeffs.a0_coeffs .* state.z2_memory);
dicklyon@473 48
dicklyon@473 49 zY = CAR_coeffs.h_coeffs .* z2; % partial output
dicklyon@473 50
dicklyon@473 51 % Ripple input-output path, instead of parallel, to avoid delay...
dicklyon@473 52 % this is the only part that doesn't get computed "in parallel":
dicklyon@473 53 in_out = x_in;
dicklyon@473 54 for ch = 1:length(zY)
dicklyon@473 55 % could do this here, or later in parallel:
dicklyon@473 56 z1(ch) = z1(ch) + in_out;
dicklyon@473 57 % ripple, saving final channel outputs in zY
dicklyon@473 58 in_out = g(ch) * (in_out + zY(ch));
dicklyon@473 59 zY(ch) = in_out;
dicklyon@473 60 end
dicklyon@473 61
dicklyon@473 62 % put new state back in place of old
dicklyon@504 63 % (z1 is a genuine temp; the others can update by reference in C)
dicklyon@473 64 state.z1_memory = z1;
dicklyon@473 65 state.z2_memory = z2;
dicklyon@473 66 state.zA_memory = zA;
dicklyon@473 67 state.zB_memory = zB;
dicklyon@473 68 state.zY_memory = zY;
dicklyon@473 69 state.g_memory = g;
dicklyon@473 70
dicklyon@504 71 car_out = zY;
dicklyon@504 72
dicklyon@504 73