comparison toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/SeneffEar.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function y = SeneffEar(x, fs, plotChannel)
2
3 % Compute the response of Stephanie Seneff's Auditory Model. The
4 % input waveform x (with sampling rate fs) is converted into fourty
5 % channels of auditory firing probabilities.
6 %
7 % This m-function is based on data from the following paper:
8 % Benjamin D. Bryant and John D. Gowdy, "Simulation of Stages
9 % I and II of Seneff's Auditory Model (SAM) Using Matlab", and
10 % published in the Proceedings of the 1993 Matlab User's Group
11 % Conference.
12 % Thanks to Benjamin Bryant for supplying us with his filter
13 % coefficients and the initial organization of this implementation.
14
15 % (c) 1998 Interval Research Corporation
16
17 global SeneffFS SeneffPreemphasis SeneffFilterBank
18 global SeneffForward SeneffBackward
19
20 if nargin < 2; fs = 16000; end
21 if nargin < 3; plotChannel = 0; end
22
23 if exist('SeneffFS') ~= 1 | length(SeneffFS) == 0 | SeneffFS ~= fs
24 [SeneffPreemphasis, SeneffFilterBank, ...
25 SeneffForward, SeneffBackward] = SeneffEarSetup(fs);
26 SeneffFS = fs;
27 end
28
29 y=soscascade(filter(SeneffPreemphasis, [1], x), ...
30 SeneffFilterBank);
31
32 [width,channels] = size(SeneffForward);
33 for j=1:channels
34 y(j,:) = filter(SeneffForward(:,j),SeneffBackward(:,j),y(j,:));
35 end
36
37 if plotChannel > 0
38 clf
39 subplot(4,2,1);
40 plot(y(plotChannel,:))
41 subplot(4,2,2);
42 f=find(y(plotChannel,:)>max(y(plotChannel,:))/20);
43 plotStart = max(1,f(1)-10);
44 plotEnd = min(plotStart+84,length(y(plotChannel,:)));
45 plot(y(plotChannel,plotStart:plotEnd));
46 ylabel('Filter Bank')
47 end
48
49 % Implement Seneff's detector non-linearity.
50 hwrA = 10;
51 hwrB = 65;
52 hwrG = 2.35;
53
54 y = hwrA*atan(hwrB*max(0,y))+exp(hwrA*hwrB*min(0,y));
55 if plotChannel > 0
56 subplot(4,2,3);
57 plot(y(plotChannel,:))
58 subplot(4,2,4);
59 plot(y(plotChannel,plotStart:plotEnd));
60 ylabel('HWR');
61 end
62
63 % Implement Seneff's short-term adaptation (a reservoir hair cell
64 % model.)
65 start_Cn = 442.96875;
66 Tua = 58.3333/fs;
67 Tub = 8.3333/fs;
68
69 len = length(x);
70 Cn = start_Cn*ones(channels,1)*0; % Does this work non zero?
71 for j=1:len
72 Sn = y(:,j);
73 flow = max(0,Tua*(Sn-Cn));
74 Cn = Cn + flow - Tub*Cn;
75 y(:,j) = flow;
76 end
77
78 % Implement Seneff's Low Pass filter (to model the loss of
79 % Synchrony.
80
81 lpAlpha = .209611;
82 lpPoly = poly([lpAlpha lpAlpha lpAlpha lpAlpha]);
83 Glp = sum(lpPoly);
84
85 for j=1:channels
86 y(j,:) = filter([Glp],lpPoly,y(j,:));
87 end
88
89 if plotChannel > 0
90 subplot(4,2,5);
91 plot(y(plotChannel,:))
92 subplot(4,2,6);
93 plot(y(plotChannel,plotStart:plotEnd));
94 ylabel('Adaptation');
95 end
96
97 % Finally implement Seneff's Adaptive Gain Control. This computes
98 % y(n) = y(n)/(1+k y'(n))
99 % where y'(n) is a low-pass filtered version of the input. Note,
100 % this is a single channel AGC.
101
102 initial_yn = 0.23071276;
103 alpha_agc = 0.979382181;
104 kagc = 0.002;
105
106 for j=1:channels
107 averageY(j,:) = filter([0 1-alpha_agc],[alpha_agc],y(j,:),initial_yn);
108 end
109 y = y./(1+kagc*averageY);
110
111 if plotChannel > 0
112 subplot(4,2,7);
113 plot(y(plotChannel,:))
114 subplot(4,2,8);
115 plot(y(plotChannel,plotStart:plotEnd));
116 ylabel('AGC');
117 end
118