diff trunk/matlab/bmm/carfac/CARFAC_hacking.m @ 563:fb602edc2d55

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 3dff17554c6d
children 3e2e0ab4f708
line wrap: on
line diff
--- a/trunk/matlab/bmm/carfac/CARFAC_hacking.m	Tue May 01 23:32:24 2012 +0000
+++ b/trunk/matlab/bmm/carfac/CARFAC_hacking.m	Sat May 12 04:31:59 2012 +0000
@@ -26,29 +26,37 @@
 if use_plan_file
   
   file_signal = wavread('plan.wav');
-  file_signal = file_signal(8100+(1:20000));  % trim for a faster test
+  %   file_signal = file_signal(8100+(1:20000));  % trim for a faster test
+  file_signal = file_signal(10000+(1:10000));  % trim for a faster test
   
 else
-    flist = [1000];
-    alist = [1];
-    flist = 1000;
-    alist = 1;
-    sine_signal = 0;
-    times = (0:19999)' / 22050;
-    for fno = 1:length(flist)
-      sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times);
-    end
-    growth_power = 0;  % use 0 for flat, 4 or more for near exponential
-    file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power);
+  flist = [1000];
+  alist = [1];
+  flist = 1000;
+  alist = 1;
+  sine_signal = 0;
+  times = (0:19999)' / 22050;
+  for fno = 1:length(flist)
+    sine_signal = sine_signal + alist(fno)*sin(flist(fno)*2*pi*times);
+  end
+  growth_power = 0;  % use 0 for flat, 4 or more for near exponential
+  file_signal = 1.0 * (sine_signal .* (times/max(times)).^growth_power);
 end
 
 % repeat with negated signal to compare responses:
 % file_signal = [file_signal; -file_signal];
 
 % make a long test signal by repeating at different levels:
-dB = -80;
-test_signal =  10^(dB/20)* file_signal(1:4000) % lead-in [];
-for dB =  -80:20:60
+do_distortion_figs = 0;  % use 1 for distortion figure hack....
+if do_distortion_figs
+  dB_list = -40:20:0
+else
+  dB_list = -80:20:60
+end
+% dB = dB_list(1);
+% test_signal =  10^(dB/20)* file_signal(1:4000) % lead-in [];
+test_signal = [];
+for dB =  dB_list
   test_signal = [test_signal; file_signal * 10^(dB/20)];
 end
 
@@ -57,28 +65,28 @@
 
 agc_plot_fig_num = 6;
 
-for n_ears = 1:2
+for n_ears = 1    %  1:2
   
   CF_struct = CARFAC_Design(n_ears);  % default design
-
+  
   if n_ears == 2
     % For the 2-channel pass, add a silent second channel:
     test_signal = [test_signal, zeros(size(test_signal))];
   end
   
   CF_struct = CARFAC_Init(CF_struct);
-
-  [CF_struct, nap_decim, nap, BM] = CARFAC_Run(CF_struct, test_signal, ...
+  
+  [CF_struct, nap_decim, nap, BM, ohc, agc] = CARFAC_Run(CF_struct, test_signal, ...
     agc_plot_fig_num);
-
-%   nap = deskew(nap);  % deskew doesn't make much difference
-
-%   dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 38:40, :).^2));
-  dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 20:50, :).^2));
-
+  
+  %   nap = deskew(nap);  % deskew doesn't make much difference
+  
+  %   dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, 20:50, :).^2));
+  dB_BM = 10/log(10) * log(filter(1, [1, -0.995], BM(:, :, :).^2));
+  
   % only ear 1:
   MultiScaleSmooth(dB_BM(5000:200:end, :, 1), 1);
-
+  
   % Display results for 1 or 2 ears:
   for ear = 1:n_ears
     smooth_nap = nap_decim(:, :, ear);
@@ -90,13 +98,59 @@
     title('smooth nap from nap decim')
     colormap(1 - gray);
   end
-
+  
   % Show resulting data, even though M-Lint complains:
   CF_struct
-  CF_struct.CAR_state
-  CF_struct.AGC_state
+  CF_struct.ears(1).CAR_state
+  CF_struct.ears(1).AGC_state
   min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
-
+  
+  %%
+  if do_distortion_figs
+    channels = [38, 39, 40];
+    times = 0000 + (3200:3599);
+    smoothed_ohc = ohc;
+    epsi = 0.4;
+    %   smoothed_ohc = filter(epsi, [1, -(1-epsi)], smoothed_ohc);
+    %   smoothed_ohc = filter(epsi, [1, -(1-epsi)], smoothed_ohc);
+    
+    figure(101); hold off
+    plot(smoothed_ohc(times, channels))
+    hold on
+    plot(smoothed_ohc(times, channels(2)), 'k-', 'LineWidth', 1.5)
+    title('OHC')
+    
+    figure(105); hold off
+    plot(agc(times, channels))
+    hold on
+    plot(agc(times, channels(2)), 'k-', 'LineWidth', 1.5)
+    title('AGC')
+    
+    figure(103); hold off
+    plot(BM(times, channels))
+    hold on
+    plot(BM(times, channels(2)), 'k-', 'LineWidth', 1.5)
+    title('BM')
+    
+    extra_damping = smoothed_ohc + agc;
+    figure(102); hold off
+    plot(extra_damping(times, channels))
+    hold on
+    plot(extra_damping(times, channels(2)), 'k-', 'LineWidth', 1.5)
+    title('extra damping')
+    
+    distortion = -(extra_damping - smooth1d(extra_damping, 10)) .* BM;
+    distortion = filter(epsi, [1, -(1-epsi)], distortion);
+    distortion = filter(epsi, [1, -(1-epsi)], distortion);
+    %   distortion = filter(epsi, [1, -(1-epsi)], distortion);
+    figure(104); hold off
+    plot(distortion(times, channels))
+    hold on
+    plot(distortion(times, channels(2)), 'k-', 'LineWidth', 1.5)
+    title('distortion')
+    
+  end
+  %%
 end
 
 % Expected result:  Figure 3 looks like figure 2, a tiny bit darker.