diff matlab/bmm/carfac/CARFAC_Run.m @ 502:37c007925536

Separate the OHC nonlinear function into new file CARFAC_OHC_NLF.m. Update Design doc a bit. Add optional outputs and hacks that I used with Roy to look at distortion effects in OHC.
author dicklyon@google.com
date Sat, 12 May 2012 04:31:59 +0000
parents 896620d9d539
children a0869cb1c99b
line wrap: on
line diff
--- a/matlab/bmm/carfac/CARFAC_Run.m	Tue May 01 23:32:24 2012 +0000
+++ b/matlab/bmm/carfac/CARFAC_Run.m	Sat May 12 04:31:59 2012 +0000
@@ -17,9 +17,9 @@
 % See the License for the specific language governing permissions and
 % limitations under the License.
 
-function [CF, decim_naps, naps, BM] = CARFAC_Run ...
+function [CF, decim_naps, naps, BM, ohc, agc] = CARFAC_Run ...
   (CF, input_waves, AGC_plot_fig_num)
-% function [CF, decim_naps, naps] = CARFAC_Run ...
+% function [CF, decim_naps, naps, BM, ohc, agc] = CARFAC_Run ...
 %   (CF, input_waves, AGC_plot_fig_num)
 % This function runs the CARFAC; that is, filters a 1 or more channel
 % sound input to make one or more neural activity patterns (naps).
@@ -38,10 +38,7 @@
 % the input_waves are assumed to be sampled at the same rate as the
 % CARFAC is designed for; a resampling may be needed before calling this.
 %
-% The function works as an outer iteration on time, updating all the
-% filters and AGC states concurrently, so that the different channels can
-% interact easily.  The inner loops are over filterbank channels, and
-% this level should be kept efficient.
+% ohc and agc are optional extra outputs for diagnosing internals.
 
 [n_samp, n_ears] = size(input_waves);
 n_ch = CF.n_ch;
@@ -56,6 +53,18 @@
   BM = [];
 end
 
+if nargout > 4
+  ohc = zeros(n_samp, n_ch, n_ears);
+else
+  ohc = [];
+end
+
+if nargout > 5
+  agc = zeros(n_samp, n_ch, n_ears);
+else
+  agc = [];
+end
+
 if n_ears ~= CF.n_ears
   error('bad number of input_waves channels passed to CARFAC_Run')
 end
@@ -89,7 +98,8 @@
   end
   % Process a segment to get a slice of decim_naps, and plot AGC state:
   if ~isempty(BM)
-    [seg_naps, CF, seg_BM] = CARFAC_Run_Segment(CF, input_waves(k_range, :));
+    % ask for everything in this case, for laziness:
+    [seg_naps, CF, seg_BM, seg_ohc, seg_agc] = CARFAC_Run_Segment(CF, input_waves(k_range, :));
   else
     [seg_naps, CF] = CARFAC_Run_Segment(CF, input_waves(k_range, :));
   end
@@ -108,6 +118,20 @@
     end
   end
   
+  if ~isempty(ohc)
+    for ear = 1:n_ears
+      % Accumulate segment naps to make full naps
+      ohc(k_range, :, ear) = seg_ohc(:, :, ear);
+    end
+  end
+  
+  if ~isempty(agc)
+    for ear = 1:n_ears
+      % Accumulate segment naps to make full naps
+      agc(k_range, :, ear) = seg_agc(:, :, ear);
+    end
+  end
+  
   if ~isempty(decim_naps)
     for ear = 1:n_ears
       decim_naps(seg_num, :, ear) = CF.ears(ear).IHC_state.ihc_accum / seglen;