Sfoglia il codice sorgente

new calibration procedure

Fernando Pablo Lopez-Lezcano 7 anni fa
parent
commit
d6fe8dedd9
1 ha cambiato i file con 24 aggiunte e 25 eliminazioni
  1. 24 25
      calibration/src/sphear_af_calibrate.m

+ 24 - 25
calibration/src/sphear_af_calibrate.m

@@ -39,37 +39,36 @@ function [] = sphear_af_calibrate(measurements, keep, fade, suffix);
   %% read the convolution kernel
   [ref, Fs] = wavread('../data/current/cal/drc-filter.wav');
 
-  %% window the DRC generated filter, eliminate the stuff before the main
-  %% peak and limit the length to the approximate useful length of the
-  %% original recorded impulse response
-  
-  [peaks, locs] = findpeaks(abs(ref));
-  [value, index] = max(peaks);
-  loc = locs(index);
-  
-  %% truncate before the main peak
-  b_len = 4;
-  before = tukeywin(2 * b_len, 0.9)(1:end/2) .* ref(loc-2*b_len:loc-b_len-1);
-  %% useful samples
-  samples = keep * Fs/2;
-  during = ref(loc-b_len:loc+samples-1);
-  %% fade out after useful samples
-  a_len = fade * Fs/2;
-  after = tukeywin(2 * a_len, 0.9)(end/2:end) .* ref(loc+samples:loc+samples+a_len);
-  %% and the whole thing is:
-  trunc = cat(1, before, during, after);
-
   capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
+  loc_min = intmax;
+  loc_max = 0;
   %% all requested measurements
   for m = measurements
+    printf("processing measurement %d\n", m);
     %% read in capsule signal and normalize it
     for c = 1:4
-      printf("processing capsule %d\n", c);
       sig = wavread(["../data/current/af/a-format-" sprintf("%s%03d", suffix, m) "-" char(capnames(c)) ".wav"]);
-      cal_sig(:,c) = conv(trunc, sig);
-      wavwrite(cal_sig(:,c), Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) "-" char(capnames(c)) ".wav"]);
-      printf("end capsule %d\n", c);
+      cal_sig(m,c,:) = conv(ref, sig);
+      %% find first non-zero sample of convolved signal
+      head = find(cal_sig(m,c,:)!=0, 1, 'first');
+      if (head < loc_min)
+	loc_min = head;
+      end
+      if (head > loc_max)
+	loc_max = head;
+      end
+    end
+  end
+  %% now write all the calibrated impulse responses
+  %% choose a arbitrary multiple of input size... sigh
+  out_size = 4 * size(sig, 1);
+  range = loc_min - 1:loc_min - 1 + out_size;
+  %% 5% end window
+  wend = tukeywin(2 * out_size, 0.9)(end/2:end)';
+  printf("start sample: min = %f, max = %f, output size = %f\n", loc_min, loc_max, out_size);
+  for m = measurements
+    for c = 1:4
+      wavwrite((cal_sig(m,c,:)(range)) .* wend, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) "-" char(capnames(c)) ".wav"]);
     end
-    wavwrite(cal_sig, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) ".wav"]);
   end
 end