annotate toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/LyonPassiveEar.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function y=LyonPassiveEar(x,sr,df,earQ,stepfactor,differ,agcf,taufactor)
wolffd@0 2 % y=LyonPassiveEar(input, sample_rate, decimation, earQ, stepfactor);
wolffd@0 3 %
wolffd@0 4 % Changes
wolffd@0 5 % Zeroed out the preemphasis channels before doing the AGC. This is needed
wolffd@0 6 % so that cochlear inversion is possible (since we don't have those channels,
wolffd@0 7 % we can't invert their gain.)..... Malcolm 6/26/95
wolffd@0 8
wolffd@0 9 % (c) 1998 Interval Research Corporation
wolffd@0 10
wolffd@0 11 if nargin < 3
wolffd@0 12 fprintf('Syntax: y=LyonPassiveEar(input, sample_rate, decimation, earQ, stepfactor)\n');
wolffd@0 13 fprintf(' The input, sample_rate, and decimation parameters are mandatory.\n');
wolffd@0 14 return;
wolffd@0 15 end
wolffd@0 16
wolffd@0 17 if df < 1; df = 1; end
wolffd@0 18 if nargin < 4; earQ = 8; end
wolffd@0 19 if nargin < 5; stepfactor = earQ/32; end
wolffd@0 20 if nargin < 6; differ=1; end
wolffd@0 21 if nargin < 7; agcf=1; end
wolffd@0 22 if nargin < 8; taufactor=3; end
wolffd@0 23
wolffd@0 24 earFilters = DesignLyonFilters(sr, earQ, stepfactor);
wolffd@0 25
wolffd@0 26 nSamples = length(x);
wolffd@0 27 nOutputSamples = floor(nSamples/df);
wolffd@0 28 [nChannels filterWidth] = size(earFilters);
wolffd@0 29
wolffd@0 30 sosOutput = zeros(nChannels, df);
wolffd@0 31 sosState = zeros(nChannels, 2);
wolffd@0 32 agcState = zeros(nChannels, 4);
wolffd@0 33 y = zeros(nChannels, nOutputSamples);
wolffd@0 34
wolffd@0 35 decEps = EpsilonFromTauFS(df/sr*taufactor,sr);
wolffd@0 36 decState = zeros(nChannels, 2);
wolffd@0 37 decFilt = SetGain([0 0 1 -2*(1-decEps) (1-decEps)^2], 1, 0, sr);
wolffd@0 38
wolffd@0 39 eps1 = EpsilonFromTauFS(.64,sr);
wolffd@0 40 eps2 = EpsilonFromTauFS(.16,sr);
wolffd@0 41 eps3 = EpsilonFromTauFS(.04,sr);
wolffd@0 42 eps4 = EpsilonFromTauFS(.01,sr);
wolffd@0 43
wolffd@0 44 tar1 = .0032;
wolffd@0 45 tar2 = .0016;
wolffd@0 46 tar3 = .0008;
wolffd@0 47 tar4 = .0004;
wolffd@0 48
wolffd@0 49 if 0
wolffd@0 50 fprintf('df=%g, earq=%g, stepfactor=%g, differ=%g\n',df,earQ,stepfactor,differ);
wolffd@0 51 fprintf('agcf=%g, taufactor=%g\n', agcf, taufactor);
wolffd@0 52 [tar1 tar2 tar3 tar4; eps1 eps2 eps3 eps4]
wolffd@0 53 end
wolffd@0 54
wolffd@0 55 for i=0:nOutputSamples-1
wolffd@0 56 [sosOutput sosState]= soscascade(x(i*df+1:i*df+df), earFilters, ...
wolffd@0 57 sosState);
wolffd@0 58 output = max(0, sosOutput); %% Half Wave Rectify
wolffd@0 59 output(1) = 0; %% Test Hack to make inversion easier.
wolffd@0 60 output(2) = 0;
wolffd@0 61 if agcf > 0
wolffd@0 62 [output agcState] = agc(output, [tar1 tar2 tar3 tar4; ...
wolffd@0 63 eps1 eps2 eps3 eps4], ...
wolffd@0 64 agcState);
wolffd@0 65 end
wolffd@0 66
wolffd@0 67 if differ > 0
wolffd@0 68 output = [output(1,:);output(1:nChannels-1,:) - ...
wolffd@0 69 output(2:nChannels,:)];
wolffd@0 70 output = max(0, output);
wolffd@0 71 end
wolffd@0 72
wolffd@0 73 if df > 1
wolffd@0 74 [output decState] = sosfilters(output, decFilt, decState);
wolffd@0 75 end
wolffd@0 76 y(:,i+1) = output(:,df);
wolffd@0 77 end
wolffd@0 78
wolffd@0 79 %y = min(y,2*tar4);
wolffd@0 80 y=y(3:nChannels,:);