annotate matlab/bmm/carfac/CARFAC_Detect.m @ 474:3a873d04a7fe

A few straggling fixes for binaural files
author dicklyon@google.com
date Fri, 16 Mar 2012 04:31:56 +0000
parents f8ba7ad93fa9
children 1d720e7fffdf
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
tom@455 20 function conductance = CARFAC_Detect(x_in)
tom@455 21 % function conductance = CARFAC_detect(x_in)
tom@455 22 % An IHC-like sigmoidal detection nonlinearity for the CARFAC.
tom@455 23 % Resulting conductance is in about [0...1.3405]
tom@455 24
tom@455 25
tom@455 26 a = 0.175; % offset of low-end tail into neg x territory
tom@455 27 % this parameter is adjusted for the book, to make the 20% DC
tom@455 28 % response threshold at 0.1
tom@455 29
tom@455 30 set = x_in > -a;
tom@455 31 z = x_in(set) + a;
tom@455 32
tom@455 33 % zero is the final answer for many points:
tom@455 34 conductance = zeros(size(x_in));
tom@455 35 conductance(set) = z.^3 ./ (z.^3 + z.^2 + 0.1);
tom@455 36
tom@455 37
tom@455 38 %% other things I tried:
tom@455 39 %
tom@455 40 % % zero is the final answer for many points:
tom@455 41 % conductance = zeros(size(x_in));
tom@455 42 %
tom@455 43 % order = 4; % 3 is a little cheaper; 4 has continuous second deriv.
tom@455 44 %
tom@455 45 % % thresholds and terms involving just a, b, s are scalar ops; x are vectors
tom@455 46 %
tom@455 47 % switch order
tom@455 48 % case 3
tom@455 49 % a = 0.15; % offset of low-end tail into neg x territory
tom@455 50 % b = 1; % 0.44; % width of poly segment
tom@455 51 % slope = 0.7;
tom@455 52 %
tom@455 53 % threshold1 = -a;
tom@455 54 % threshold2 = b - a;
tom@455 55 %
tom@455 56 % set2 = x_in > threshold2;
tom@455 57 % set1 = x_in > threshold1 & ~set2;
tom@455 58 %
tom@455 59 % s = slope/(2*b - 3/2*b^2); % factor to make slope at breakpoint
tom@455 60 % t = s * (b^2 - (b^3) / 2);
tom@455 61 %
tom@455 62 % x = x_in(set1) - threshold1;
tom@455 63 % conductance(set1) = s * x .* (x - x .* x / 2); % x.^2 - 0.5x.^3
tom@455 64 %
tom@455 65 % x = x_in(set2) - threshold2;
tom@455 66 % conductance(set2) = t + slope * x ./ (1 + x);
tom@455 67 %
tom@455 68 %
tom@455 69 % case 4
tom@455 70 % a = 0.24; % offset of low-end tail into neg x territory
tom@455 71 % b = 0.57; % width of poly segment; 0.5 to end at zero curvature,
tom@455 72 % a = 0.18; % offset of low-end tail into neg x territory
tom@455 73 % b = 0.57; % width of poly segment; 0.5 to end at zero curvature,
tom@455 74 % % 0.57 to approx. match curvature of the upper segment.
tom@455 75 % threshold1 = -a;
tom@455 76 % threshold2 = b - a;
tom@455 77 %
tom@455 78 %
tom@455 79 % set2 = x_in > threshold2;
tom@455 80 % set1 = x_in > threshold1 & ~set2;
tom@455 81 %
tom@455 82 % s = 1/(3*b^2 - 4*b^3); % factor to make slope 1 at breakpoint
tom@455 83 % t = s * (b^3 - b^4);
tom@455 84 %
tom@455 85 % x = x_in(set1) - threshold1;
tom@455 86 % conductance(set1) = s * x .* x .* (x - x .* x); % x.^3 - x.^4
tom@455 87 %
tom@455 88 % x = x_in(set2) - threshold2;
tom@455 89 % conductance(set2) = t + x ./ (1 + x);
tom@455 90 %
tom@455 91 % end
tom@455 92 %