tom@516: % Copyright 2012, Google, Inc. tom@516: % Author: Richard F. Lyon tom@516: % tom@516: % This Matlab file is part of an implementation of Lyon's cochlear model: tom@516: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" tom@516: % to supplement Lyon's upcoming book "Human and Machine Hearing" tom@516: % tom@516: % Licensed under the Apache License, Version 2.0 (the "License"); tom@516: % you may not use this file except in compliance with the License. tom@516: % You may obtain a copy of the License at tom@516: % tom@516: % http://www.apache.org/licenses/LICENSE-2.0 tom@516: % tom@516: % Unless required by applicable law or agreed to in writing, software tom@516: % distributed under the License is distributed on an "AS IS" BASIS, tom@516: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tom@516: % See the License for the specific language governing permissions and tom@516: % limitations under the License. tom@516: tom@516: function conductance = CARFAC_Detect(x_in) tom@516: % function conductance = CARFAC_detect(x_in) tom@516: % An IHC-like sigmoidal detection nonlinearity for the CARFAC. tom@516: % Resulting conductance is in about [0...1.3405] tom@516: tom@516: tom@516: a = 0.175; % offset of low-end tail into neg x territory tom@516: % this parameter is adjusted for the book, to make the 20% DC tom@516: % response threshold at 0.1 tom@516: tom@516: set = x_in > -a; tom@516: z = x_in(set) + a; tom@516: tom@516: % zero is the final answer for many points: tom@516: conductance = zeros(size(x_in)); tom@516: conductance(set) = z.^3 ./ (z.^3 + z.^2 + 0.1); tom@516: tom@516: tom@516: %% other things I tried: tom@516: % tom@516: % % zero is the final answer for many points: tom@516: % conductance = zeros(size(x_in)); tom@516: % tom@516: % order = 4; % 3 is a little cheaper; 4 has continuous second deriv. tom@516: % tom@516: % % thresholds and terms involving just a, b, s are scalar ops; x are vectors tom@516: % tom@516: % switch order tom@516: % case 3 tom@516: % a = 0.15; % offset of low-end tail into neg x territory tom@516: % b = 1; % 0.44; % width of poly segment tom@516: % slope = 0.7; tom@516: % tom@516: % threshold1 = -a; tom@516: % threshold2 = b - a; tom@516: % tom@516: % set2 = x_in > threshold2; tom@516: % set1 = x_in > threshold1 & ~set2; tom@516: % tom@516: % s = slope/(2*b - 3/2*b^2); % factor to make slope at breakpoint tom@516: % t = s * (b^2 - (b^3) / 2); tom@516: % tom@516: % x = x_in(set1) - threshold1; tom@516: % conductance(set1) = s * x .* (x - x .* x / 2); % x.^2 - 0.5x.^3 tom@516: % tom@516: % x = x_in(set2) - threshold2; tom@516: % conductance(set2) = t + slope * x ./ (1 + x); tom@516: % tom@516: % tom@516: % case 4 tom@516: % a = 0.24; % offset of low-end tail into neg x territory tom@516: % b = 0.57; % width of poly segment; 0.5 to end at zero curvature, tom@516: % a = 0.18; % offset of low-end tail into neg x territory tom@516: % b = 0.57; % width of poly segment; 0.5 to end at zero curvature, tom@516: % % 0.57 to approx. match curvature of the upper segment. tom@516: % threshold1 = -a; tom@516: % threshold2 = b - a; tom@516: % tom@516: % tom@516: % set2 = x_in > threshold2; tom@516: % set1 = x_in > threshold1 & ~set2; tom@516: % tom@516: % s = 1/(3*b^2 - 4*b^3); % factor to make slope 1 at breakpoint tom@516: % t = s * (b^3 - b^4); tom@516: % tom@516: % x = x_in(set1) - threshold1; tom@516: % conductance(set1) = s * x .* x .* (x - x .* x); % x.^3 - x.^4 tom@516: % tom@516: % x = x_in(set2) - threshold2; tom@516: % conductance(set2) = t + x ./ (1 + x); tom@516: % tom@516: % end tom@516: %