annotate trunk/matlab/bmm/carfac/CARFAC_Detect.m @ 548:ff12d0432d9c

Implemented all but g0 initialisation in CAR class
author Ulf.Hammarqvist@gmail.com
date Sat, 07 Apr 2012 09:35:10 +0000
parents 68c15d43fcc8
children 101289a936be
rev   line source
tom@516 1 % Copyright 2012, Google, Inc.
tom@516 2 % Author: Richard F. Lyon
tom@516 3 %
tom@516 4 % This Matlab file is part of an implementation of Lyon's cochlear model:
tom@516 5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
tom@516 6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
tom@516 7 %
tom@516 8 % Licensed under the Apache License, Version 2.0 (the "License");
tom@516 9 % you may not use this file except in compliance with the License.
tom@516 10 % You may obtain a copy of the License at
tom@516 11 %
tom@516 12 % http://www.apache.org/licenses/LICENSE-2.0
tom@516 13 %
tom@516 14 % Unless required by applicable law or agreed to in writing, software
tom@516 15 % distributed under the License is distributed on an "AS IS" BASIS,
tom@516 16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tom@516 17 % See the License for the specific language governing permissions and
tom@516 18 % limitations under the License.
tom@516 19
tom@516 20 function conductance = CARFAC_Detect(x_in)
tom@516 21 % function conductance = CARFAC_detect(x_in)
tom@516 22 % An IHC-like sigmoidal detection nonlinearity for the CARFAC.
tom@516 23 % Resulting conductance is in about [0...1.3405]
tom@516 24
tom@516 25
tom@516 26 a = 0.175; % offset of low-end tail into neg x territory
tom@516 27 % this parameter is adjusted for the book, to make the 20% DC
tom@516 28 % response threshold at 0.1
tom@516 29
tom@516 30 set = x_in > -a;
tom@516 31 z = x_in(set) + a;
tom@516 32
tom@516 33 % zero is the final answer for many points:
tom@516 34 conductance = zeros(size(x_in));
tom@516 35 conductance(set) = z.^3 ./ (z.^3 + z.^2 + 0.1);
tom@516 36
tom@516 37
tom@516 38 %% other things I tried:
tom@516 39 %
tom@516 40 % % zero is the final answer for many points:
tom@516 41 % conductance = zeros(size(x_in));
tom@516 42 %
tom@516 43 % order = 4; % 3 is a little cheaper; 4 has continuous second deriv.
tom@516 44 %
tom@516 45 % % thresholds and terms involving just a, b, s are scalar ops; x are vectors
tom@516 46 %
tom@516 47 % switch order
tom@516 48 % case 3
tom@516 49 % a = 0.15; % offset of low-end tail into neg x territory
tom@516 50 % b = 1; % 0.44; % width of poly segment
tom@516 51 % slope = 0.7;
tom@516 52 %
tom@516 53 % threshold1 = -a;
tom@516 54 % threshold2 = b - a;
tom@516 55 %
tom@516 56 % set2 = x_in > threshold2;
tom@516 57 % set1 = x_in > threshold1 & ~set2;
tom@516 58 %
tom@516 59 % s = slope/(2*b - 3/2*b^2); % factor to make slope at breakpoint
tom@516 60 % t = s * (b^2 - (b^3) / 2);
tom@516 61 %
tom@516 62 % x = x_in(set1) - threshold1;
tom@516 63 % conductance(set1) = s * x .* (x - x .* x / 2); % x.^2 - 0.5x.^3
tom@516 64 %
tom@516 65 % x = x_in(set2) - threshold2;
tom@516 66 % conductance(set2) = t + slope * x ./ (1 + x);
tom@516 67 %
tom@516 68 %
tom@516 69 % case 4
tom@516 70 % a = 0.24; % offset of low-end tail into neg x territory
tom@516 71 % b = 0.57; % width of poly segment; 0.5 to end at zero curvature,
tom@516 72 % a = 0.18; % offset of low-end tail into neg x territory
tom@516 73 % b = 0.57; % width of poly segment; 0.5 to end at zero curvature,
tom@516 74 % % 0.57 to approx. match curvature of the upper segment.
tom@516 75 % threshold1 = -a;
tom@516 76 % threshold2 = b - a;
tom@516 77 %
tom@516 78 %
tom@516 79 % set2 = x_in > threshold2;
tom@516 80 % set1 = x_in > threshold1 & ~set2;
tom@516 81 %
tom@516 82 % s = 1/(3*b^2 - 4*b^3); % factor to make slope 1 at breakpoint
tom@516 83 % t = s * (b^3 - b^4);
tom@516 84 %
tom@516 85 % x = x_in(set1) - threshold1;
tom@516 86 % conductance(set1) = s * x .* x .* (x - x .* x); % x.^3 - x.^4
tom@516 87 %
tom@516 88 % x = x_in(set2) - threshold2;
tom@516 89 % conductance(set2) = t + x ./ (1 + x);
tom@516 90 %
tom@516 91 % end
tom@516 92 %